Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library index.split.store; | 5 library index.split.store; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 return index; | 100 return index; |
| 101 } | 101 } |
| 102 | 102 |
| 103 List<String> _getLocationComponents(List<int> path) { | 103 List<String> _getLocationComponents(List<int> path) { |
| 104 int length = path.length; | 104 int length = path.length; |
| 105 List<String> components = new List<String>(); | 105 List<String> components = new List<String>(); |
| 106 for (int i = 0; i < length; i++) { | 106 for (int i = 0; i < length; i++) { |
| 107 int componentId = path[i]; | 107 int componentId = path[i]; |
| 108 String component = _stringCodec.decode(componentId); | 108 String component = _stringCodec.decode(componentId); |
| 109 if (i < length - 1 && path[i + 1] < 0) { | 109 if (i < length - 1 && path[i + 1] < 0) { |
| 110 component += "@${(-path[i + 1])}"; | 110 component += '@${(-path[i + 1])}'; |
| 111 i++; | 111 i++; |
| 112 } | 112 } |
| 113 components.add(component); | 113 components.add(component); |
| 114 } | 114 } |
| 115 return components; | 115 return components; |
| 116 } | 116 } |
| 117 | 117 |
| 118 List<int> _getLocationPath(Element element) { | 118 List<int> _getLocationPath(Element element) { |
| 119 List<String> components = element.location.components; | 119 List<String> components = element.location.components; |
| 120 int length = components.length; | 120 int length = components.length; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 214 |
| 215 @override | 215 @override |
| 216 Future<IndexNode> getNode(String name) { | 216 Future<IndexNode> getNode(String name) { |
| 217 return _fileManager.read(name).then((List<int> bytes) { | 217 return _fileManager.read(name).then((List<int> bytes) { |
| 218 if (bytes == null) { | 218 if (bytes == null) { |
| 219 return null; | 219 return null; |
| 220 } | 220 } |
| 221 _DataInputStream stream = new _DataInputStream(bytes); | 221 _DataInputStream stream = new _DataInputStream(bytes); |
| 222 return _readNode(stream); | 222 return _readNode(stream); |
| 223 }).catchError((e, stackTrace) { | 223 }).catchError((e, stackTrace) { |
| 224 _logger.logError2("Exception during reading index file ${name}", | 224 _logger.logError2('Exception during reading index file ${name}', |
| 225 new CaughtException(e, stackTrace)); | 225 new CaughtException(e, stackTrace)); |
| 226 }); | 226 }); |
| 227 } | 227 } |
| 228 | 228 |
| 229 @override | 229 @override |
| 230 IndexNode newNode(AnalysisContext context) => new IndexNode(context, | 230 IndexNode newNode(AnalysisContext context) => new IndexNode(context, |
| 231 elementCodec, _relationshipCodec); | 231 elementCodec, _relationshipCodec); |
| 232 | 232 |
| 233 @override | 233 @override |
| 234 Future putNode(String name, IndexNode node) { | 234 Future putNode(String name, IndexNode node) { |
| 235 // update location count | 235 // update location count |
| 236 { | 236 { |
| 237 _locationCount -= _getLocationCount(name); | 237 _locationCount -= _getLocationCount(name); |
| 238 int nodeLocationCount = node.locationCount; | 238 int nodeLocationCount = node.locationCount; |
| 239 _nodeLocationCounts[name] = nodeLocationCount; | 239 _nodeLocationCounts[name] = nodeLocationCount; |
| 240 _locationCount += nodeLocationCount; | 240 _locationCount += nodeLocationCount; |
| 241 } | 241 } |
| 242 // write the node | 242 // write the node |
| 243 return new Future.microtask(() { | 243 return new Future.microtask(() { |
| 244 _DataOutputStream stream = new _DataOutputStream(); | 244 _DataOutputStream stream = new _DataOutputStream(); |
| 245 _writeNode(node, stream); | 245 _writeNode(node, stream); |
| 246 var bytes = stream.getBytes(); | 246 var bytes = stream.getBytes(); |
| 247 return _fileManager.write(name, bytes); | 247 return _fileManager.write(name, bytes); |
| 248 }).catchError((e, stackTrace) { | 248 }).catchError((e, stackTrace) { |
| 249 _logger.logError2("Exception during reading index file ${name}", | 249 _logger.logError2('Exception during reading index file ${name}', |
| 250 new CaughtException(e, stackTrace)); | 250 new CaughtException(e, stackTrace)); |
| 251 }); | 251 }); |
| 252 } | 252 } |
| 253 | 253 |
| 254 @override | 254 @override |
| 255 void removeNode(String name) { | 255 void removeNode(String name) { |
| 256 // update location count | 256 // update location count |
| 257 _locationCount -= _getLocationCount(name); | 257 _locationCount -= _getLocationCount(name); |
| 258 _nodeLocationCounts.remove(name); | 258 _nodeLocationCounts.remove(name); |
| 259 // remove node | 259 // remove node |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 277 int length = stream.readInt(); | 277 int length = stream.readInt(); |
| 278 return new LocationData.forData(elementId, offset, length); | 278 return new LocationData.forData(elementId, offset, length); |
| 279 } | 279 } |
| 280 | 280 |
| 281 IndexNode _readNode(_DataInputStream stream) { | 281 IndexNode _readNode(_DataInputStream stream) { |
| 282 // check version | 282 // check version |
| 283 { | 283 { |
| 284 int version = stream.readInt(); | 284 int version = stream.readInt(); |
| 285 if (version != _VERSION) { | 285 if (version != _VERSION) { |
| 286 throw new StateError( | 286 throw new StateError( |
| 287 "Version ${_VERSION} expected, but ${version} found."); | 287 'Version ${_VERSION} expected, but ${version} found.'); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 // context | 290 // context |
| 291 int contextId = stream.readInt(); | 291 int contextId = stream.readInt(); |
| 292 AnalysisContext context = contextCodec.decode(contextId); | 292 AnalysisContext context = contextCodec.decode(contextId); |
| 293 if (context == null) { | 293 if (context == null) { |
| 294 return null; | 294 return null; |
| 295 } | 295 } |
| 296 // relations | 296 // relations |
| 297 Map<RelationKeyData, List<LocationData>> relations = {}; | 297 Map<RelationKeyData, List<LocationData>> relations = {}; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 /** | 654 /** |
| 655 * An [IndexStore] which keeps index information in separate nodes for each unit . | 655 * An [IndexStore] which keeps index information in separate nodes for each unit . |
| 656 */ | 656 */ |
| 657 class SplitIndexStore implements IndexStore { | 657 class SplitIndexStore implements IndexStore { |
| 658 /** | 658 /** |
| 659 * The [ContextCodec] to encode/decode [AnalysisContext]s. | 659 * The [ContextCodec] to encode/decode [AnalysisContext]s. |
| 660 */ | 660 */ |
| 661 ContextCodec _contextCodec; | 661 ContextCodec _contextCodec; |
| 662 | 662 |
| 663 /** | 663 /** |
| 664 * Information about "universe" elements. We need to keep them together to avo id loading of all | 664 * Information about 'universe' elements. We need to keep them together to avo id loading of all |
|
Paul Berry
2014/06/20 18:01:51
Did you really mean to make this change?
scheglov
2014/06/20 18:21:15
No, I didn't.
Fixed.
| |
| 665 * index nodes. | 665 * index nodes. |
| 666 * | 666 * |
| 667 * Order of keys: contextId, nodeId, Relationship. | 667 * Order of keys: contextId, nodeId, Relationship. |
| 668 */ | 668 */ |
| 669 Map<int, Map<int, Map<Relationship, List<LocationData>>>> | 669 Map<int, Map<int, Map<Relationship, List<LocationData>>>> |
| 670 _contextNodeRelations = new HashMap<int, Map<int, Map<Relationship, | 670 _contextNodeRelations = new HashMap<int, Map<int, Map<Relationship, |
| 671 List<LocationData>>>>(); | 671 List<LocationData>>>>(); |
| 672 | 672 |
| 673 /** | 673 /** |
| 674 * The mapping of library [Source] to the [Source]s of part units. | 674 * The mapping of library [Source] to the [Source]s of part units. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 StringCodec _stringCodec; | 717 StringCodec _stringCodec; |
| 718 | 718 |
| 719 SplitIndexStore(this._nodeManager) { | 719 SplitIndexStore(this._nodeManager) { |
| 720 this._contextCodec = _nodeManager.contextCodec; | 720 this._contextCodec = _nodeManager.contextCodec; |
| 721 this._elementCodec = _nodeManager.elementCodec; | 721 this._elementCodec = _nodeManager.elementCodec; |
| 722 this._stringCodec = _nodeManager.stringCodec; | 722 this._stringCodec = _nodeManager.stringCodec; |
| 723 } | 723 } |
| 724 | 724 |
| 725 @override | 725 @override |
| 726 String get statistics => | 726 String get statistics => |
| 727 "[${_nodeManager.locationCount} locations, ${_sources.length} sources, ${_ nameToNodeNames.length} names]"; | 727 '[${_nodeManager.locationCount} locations, ${_sources.length} sources, ${_ nameToNodeNames.length} names]'; |
| 728 | 728 |
| 729 @override | 729 @override |
| 730 bool aboutToIndexDart(AnalysisContext context, | 730 bool aboutToIndexDart(AnalysisContext context, |
| 731 CompilationUnitElement unitElement) { | 731 CompilationUnitElement unitElement) { |
| 732 context = _unwrapContext(context); | 732 context = _unwrapContext(context); |
| 733 // may be already disposed in other thread | 733 // may be already disposed in other thread |
| 734 if (context.isDisposed) { | 734 if (context.isDisposed) { |
| 735 return false; | 735 return false; |
| 736 } | 736 } |
| 737 // validate unit | 737 // validate unit |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 // remember library/unit relations | 778 // remember library/unit relations |
| 779 _recordUnitInLibrary(context, library, unit); | 779 _recordUnitInLibrary(context, library, unit); |
| 780 _recordLibraryWithUnit(context, library, unit); | 780 _recordLibraryWithUnit(context, library, unit); |
| 781 _sources.add(library); | 781 _sources.add(library); |
| 782 _sources.add(unit); | 782 _sources.add(unit); |
| 783 // prepare node | 783 // prepare node |
| 784 String libraryName = library.fullName; | 784 String libraryName = library.fullName; |
| 785 String unitName = unit.fullName; | 785 String unitName = unit.fullName; |
| 786 int libraryNameIndex = _stringCodec.encode(libraryName); | 786 int libraryNameIndex = _stringCodec.encode(libraryName); |
| 787 int unitNameIndex = _stringCodec.encode(unitName); | 787 int unitNameIndex = _stringCodec.encode(unitName); |
| 788 _currentNodeName = "${libraryNameIndex}_${unitNameIndex}.index"; | 788 _currentNodeName = '${libraryNameIndex}_${unitNameIndex}.index'; |
| 789 _currentNodeNameId = _stringCodec.encode(_currentNodeName); | 789 _currentNodeNameId = _stringCodec.encode(_currentNodeName); |
| 790 _currentNode = _nodeManager.newNode(context); | 790 _currentNode = _nodeManager.newNode(context); |
| 791 _currentContextId = _contextCodec.encode(context); | 791 _currentContextId = _contextCodec.encode(context); |
| 792 // remove Universe information for the current node | 792 // remove Universe information for the current node |
| 793 for (Map<int, dynamic> nodeRelations in _contextNodeRelations.values) { | 793 for (Map<int, dynamic> nodeRelations in _contextNodeRelations.values) { |
| 794 nodeRelations.remove(_currentNodeNameId); | 794 nodeRelations.remove(_currentNodeNameId); |
| 795 } | 795 } |
| 796 // done | 796 // done |
| 797 return true; | 797 return true; |
| 798 } | 798 } |
| 799 | 799 |
| 800 @override | 800 @override |
| 801 bool aboutToIndexHtml(AnalysisContext context, HtmlElement htmlElement) { | 801 bool aboutToIndexHtml(AnalysisContext context, HtmlElement htmlElement) { |
| 802 context = _unwrapContext(context); | 802 context = _unwrapContext(context); |
| 803 // may be already disposed in other thread | 803 // may be already disposed in other thread |
| 804 if (context.isDisposed) { | 804 if (context.isDisposed) { |
| 805 return false; | 805 return false; |
| 806 } | 806 } |
| 807 // remove locations | 807 // remove locations |
| 808 Source source = htmlElement.source; | 808 Source source = htmlElement.source; |
| 809 _removeLocations(context, null, source); | 809 _removeLocations(context, null, source); |
| 810 // remember library/unit relations | 810 // remember library/unit relations |
| 811 _recordUnitInLibrary(context, null, source); | 811 _recordUnitInLibrary(context, null, source); |
| 812 // prepare node | 812 // prepare node |
| 813 String sourceName = source.fullName; | 813 String sourceName = source.fullName; |
| 814 int sourceNameIndex = _stringCodec.encode(sourceName); | 814 int sourceNameIndex = _stringCodec.encode(sourceName); |
| 815 _currentNodeName = "${sourceNameIndex}.index"; | 815 _currentNodeName = '${sourceNameIndex}.index'; |
| 816 _currentNodeNameId = _stringCodec.encode(_currentNodeName); | 816 _currentNodeNameId = _stringCodec.encode(_currentNodeName); |
| 817 _currentNode = _nodeManager.newNode(context); | 817 _currentNode = _nodeManager.newNode(context); |
| 818 return true; | 818 return true; |
| 819 } | 819 } |
| 820 | 820 |
| 821 @override | 821 @override |
| 822 void clear() { | 822 void clear() { |
| 823 _nodeManager.clear(); | 823 _nodeManager.clear(); |
| 824 _nameToNodeNames.clear(); | 824 _nameToNodeNames.clear(); |
| 825 } | 825 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 | 1054 |
| 1055 /** | 1055 /** |
| 1056 * Removes locations recorded in the given library/unit pair. | 1056 * Removes locations recorded in the given library/unit pair. |
| 1057 */ | 1057 */ |
| 1058 void _removeLocations(AnalysisContext context, Source library, Source unit) { | 1058 void _removeLocations(AnalysisContext context, Source library, Source unit) { |
| 1059 // remove node | 1059 // remove node |
| 1060 String libraryName = library != null ? library.fullName : null; | 1060 String libraryName = library != null ? library.fullName : null; |
| 1061 String unitName = unit.fullName; | 1061 String unitName = unit.fullName; |
| 1062 int libraryNameIndex = _stringCodec.encode(libraryName); | 1062 int libraryNameIndex = _stringCodec.encode(libraryName); |
| 1063 int unitNameIndex = _stringCodec.encode(unitName); | 1063 int unitNameIndex = _stringCodec.encode(unitName); |
| 1064 String nodeName = "${libraryNameIndex}_${unitNameIndex}.index"; | 1064 String nodeName = '${libraryNameIndex}_${unitNameIndex}.index'; |
| 1065 _nodeManager.removeNode(nodeName); | 1065 _nodeManager.removeNode(nodeName); |
| 1066 // remove source | 1066 // remove source |
| 1067 _sources.remove(library); | 1067 _sources.remove(library); |
| 1068 _sources.remove(unit); | 1068 _sources.remove(unit); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 /** | 1071 /** |
| 1072 * When logging is on, [AnalysisEngine] actually creates | 1072 * When logging is on, [AnalysisEngine] actually creates |
| 1073 * [InstrumentedAnalysisContextImpl], which wraps [AnalysisContextImpl] used t o create | 1073 * [InstrumentedAnalysisContextImpl], which wraps [AnalysisContextImpl] used t o create |
| 1074 * actual [Element]s. So, in index we have to unwrap [InstrumentedAnalysisCont extImpl] | 1074 * actual [Element]s. So, in index we have to unwrap [InstrumentedAnalysisCont extImpl] |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1141 return new Uint8List.fromList(_buffer.takeBytes()); | 1141 return new Uint8List.fromList(_buffer.takeBytes()); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 void writeInt(int value) { | 1144 void writeInt(int value) { |
| 1145 _buffer.addByte((value & 0xFF000000) >> 24); | 1145 _buffer.addByte((value & 0xFF000000) >> 24); |
| 1146 _buffer.addByte((value & 0x00FF0000) >> 16); | 1146 _buffer.addByte((value & 0x00FF0000) >> 16); |
| 1147 _buffer.addByte((value & 0x0000FF00) >> 8); | 1147 _buffer.addByte((value & 0x0000FF00) >> 8); |
| 1148 _buffer.addByte(value & 0xFF); | 1148 _buffer.addByte(value & 0xFF); |
| 1149 } | 1149 } |
| 1150 } | 1150 } |
| OLD | NEW |