| Index: pkg/analyzer/lib/src/summary/index_unit.dart
|
| diff --git a/pkg/analyzer/lib/src/summary/index_unit.dart b/pkg/analyzer/lib/src/summary/index_unit.dart
|
| index 56da1861d424ca6d731531f0edd19b85988c7c2a..ca57e80da588559f9dbd7fe931654864b31ccb36 100644
|
| --- a/pkg/analyzer/lib/src/summary/index_unit.dart
|
| +++ b/pkg/analyzer/lib/src/summary/index_unit.dart
|
| @@ -33,26 +33,20 @@ class PackageIndexAssembler {
|
|
|
| /**
|
| * Each item of this list corresponds to the library URI of a unique
|
| - * [CompilationUnitElement]. It is an index into [_strings].
|
| + * [CompilationUnitElement].
|
| */
|
| - final List<int> _unitLibraryUris = <int>[];
|
| + final List<_StringInfo> _unitLibraryUris = <_StringInfo>[];
|
|
|
| /**
|
| * Each item of this list corresponds to the unit URI of a unique
|
| - * [CompilationUnitElement]. It is an index into [_strings].
|
| + * [CompilationUnitElement].
|
| */
|
| - final List<int> _unitUnitUris = <int>[];
|
| + final List<_StringInfo> _unitUnitUris = <_StringInfo>[];
|
|
|
| /**
|
| - * Map associating strings with their identifiers, which are indices
|
| - * into [_strings].
|
| + * Map associating strings with their [_StringInfo]s.
|
| */
|
| - final Map<String, int> _stringMap = <String, int>{};
|
| -
|
| - /**
|
| - * List of unique strings used in this index.
|
| - */
|
| - final List<String> _strings = <String>[];
|
| + final Map<String, _StringInfo> _stringMap = <String, _StringInfo>{};
|
|
|
| /**
|
| * List of information about each unit indexed in this index.
|
| @@ -64,6 +58,15 @@ class PackageIndexAssembler {
|
| * [index].
|
| */
|
| PackageIndexBuilder assemble() {
|
| + // sort strings end set IDs
|
| + List<_StringInfo> stringInfoList = _stringMap.values.toList();
|
| + stringInfoList.sort((a, b) {
|
| + return a.value.compareTo(b.value);
|
| + });
|
| + for (int i = 0; i < stringInfoList.length; i++) {
|
| + stringInfoList[i].id = i;
|
| + }
|
| + // sort elements and set IDs
|
| List<_ElementInfo> elementInfoList = _elementMap.values.toList();
|
| elementInfoList.sort((a, b) {
|
| return a.offset - b.offset;
|
| @@ -72,12 +75,12 @@ class PackageIndexAssembler {
|
| elementInfoList[i].id = i;
|
| }
|
| return new PackageIndexBuilder(
|
| - unitLibraryUris: _unitLibraryUris,
|
| - unitUnitUris: _unitUnitUris,
|
| + unitLibraryUris: _unitLibraryUris.map((s) => s.id).toList(),
|
| + unitUnitUris: _unitUnitUris.map((s) => s.id).toList(),
|
| elementUnits: elementInfoList.map((e) => e.unitId).toList(),
|
| elementOffsets: elementInfoList.map((e) => e.offset).toList(),
|
| elementKinds: elementInfoList.map((e) => e.kind).toList(),
|
| - strings: _strings,
|
| + strings: stringInfoList.map((s) => s.value).toList(),
|
| units: _units.map((unit) => unit.assemble()).toList());
|
| }
|
|
|
| @@ -112,14 +115,12 @@ class PackageIndexAssembler {
|
| }
|
|
|
| /**
|
| - * Add information about [str] to [_strings] if necessary, and return the
|
| - * location in this array representing [str].
|
| + * Return the unique [_StringInfo] corresponding the [str]. The field
|
| + * [_StringInfo.id] is filled by [assemble] during final sorting.
|
| */
|
| - int _getStringId(String str) {
|
| + _StringInfo _getStringInfo(String str) {
|
| return _stringMap.putIfAbsent(str, () {
|
| - int id = _strings.length;
|
| - _strings.add(str);
|
| - return id;
|
| + return new _StringInfo(str);
|
| });
|
| }
|
|
|
| @@ -132,18 +133,19 @@ class PackageIndexAssembler {
|
| return _unitMap.putIfAbsent(unitElement, () {
|
| assert(_unitLibraryUris.length == _unitUnitUris.length);
|
| int id = _unitUnitUris.length;
|
| - _unitLibraryUris.add(_getUriId(unitElement.library.source.uri));
|
| - _unitUnitUris.add(_getUriId(unitElement.source.uri));
|
| + _unitLibraryUris.add(_getUriInfo(unitElement.library.source.uri));
|
| + _unitUnitUris.add(_getUriInfo(unitElement.source.uri));
|
| return id;
|
| });
|
| }
|
|
|
| /**
|
| - * Return the identifier corresponding to [uri].
|
| + * Return the unique [_StringInfo] corresponding [uri]. The field
|
| + * [_StringInfo.id] is filled by [assemble] during final sorting.
|
| */
|
| - int _getUriId(Uri uri) {
|
| + _StringInfo _getUriInfo(Uri uri) {
|
| String str = uri.toString();
|
| - return _getStringId(str);
|
| + return _getStringInfo(str);
|
| }
|
|
|
| /**
|
| @@ -187,9 +189,10 @@ class PackageIndexAssembler {
|
| */
|
| class _DefinedNameInfo {
|
| /**
|
| - * The identifier of the name returned [PackageIndexAssembler._getStringId].
|
| + * The information about the name returned from
|
| + * [PackageIndexAssembler._getStringInfo].
|
| */
|
| - final int nameId;
|
| + final _StringInfo nameInfo;
|
|
|
| /**
|
| * The coarse-grained kind of the defined name.
|
| @@ -201,7 +204,7 @@ class _DefinedNameInfo {
|
| */
|
| final int offset;
|
|
|
| - _DefinedNameInfo(this.nameId, this.kind, this.offset);
|
| + _DefinedNameInfo(this.nameInfo, this.kind, this.offset);
|
| }
|
|
|
| /**
|
| @@ -233,6 +236,24 @@ class _ElementInfo {
|
| }
|
|
|
| /**
|
| + * Information about a string referenced in the index.
|
| + */
|
| +class _StringInfo {
|
| + /**
|
| + * The value of the string.
|
| + */
|
| + final String value;
|
| +
|
| + /**
|
| + * The unique id of the string. It is set after indexing of the whole
|
| + * package is done and we are assembling the full package index.
|
| + */
|
| + int id;
|
| +
|
| + _StringInfo(this.value);
|
| +}
|
| +
|
| +/**
|
| * Information about a single relation. Any [_ElementRelationInfo] is always
|
| * part of a [_UnitIndexAssembler], so [offset] and [length] should be
|
| * understood within the context of the compilation unit pointed to by the
|
| @@ -649,13 +670,14 @@ class _IndexContributor extends GeneralizingAstVisitor {
|
| */
|
| class _NameRelationInfo {
|
| /**
|
| - * The identifier of the name returned [PackageIndexAssembler._getStringId].
|
| + * The information about the name returned from
|
| + * [PackageIndexAssembler._getStringInfo].
|
| */
|
| - final int nameId;
|
| + final _StringInfo nameInfo;
|
| final IndexRelationKind kind;
|
| final int offset;
|
|
|
| - _NameRelationInfo(this.nameId, this.kind, this.offset);
|
| + _NameRelationInfo(this.nameInfo, this.kind, this.offset);
|
| }
|
|
|
| /**
|
| @@ -689,7 +711,7 @@ class _UnitIndexAssembler {
|
| }
|
|
|
| void addNameRelation(String name, IndexRelationKind kind, int offset) {
|
| - int nameId = pkg._getStringId(name);
|
| + _StringInfo nameId = pkg._getStringInfo(name);
|
| nameRelations.add(new _NameRelationInfo(nameId, kind, offset));
|
| }
|
|
|
| @@ -699,17 +721,17 @@ class _UnitIndexAssembler {
|
| */
|
| UnitIndexBuilder assemble() {
|
| definedNames.sort((a, b) {
|
| - return a.nameId - b.nameId;
|
| + return a.nameInfo.id - b.nameInfo.id;
|
| });
|
| elementRelations.sort((a, b) {
|
| return a.elementInfo.id - b.elementInfo.id;
|
| });
|
| nameRelations.sort((a, b) {
|
| - return a.nameId - b.nameId;
|
| + return a.nameInfo.id - b.nameInfo.id;
|
| });
|
| return new UnitIndexBuilder(
|
| unit: unitId,
|
| - definedNames: definedNames.map((n) => n.nameId).toList(),
|
| + definedNames: definedNames.map((n) => n.nameInfo.id).toList(),
|
| definedNameKinds: definedNames.map((n) => n.kind).toList(),
|
| definedNameOffsets: definedNames.map((n) => n.offset).toList(),
|
| usedElements: elementRelations.map((r) => r.elementInfo.id).toList(),
|
| @@ -718,13 +740,13 @@ class _UnitIndexAssembler {
|
| usedElementLengths: elementRelations.map((r) => r.length).toList(),
|
| usedElementIsQualifiedFlags:
|
| elementRelations.map((r) => r.isQualified).toList(),
|
| - usedNames: nameRelations.map((r) => r.nameId).toList(),
|
| + usedNames: nameRelations.map((r) => r.nameInfo.id).toList(),
|
| usedNameKinds: nameRelations.map((r) => r.kind).toList(),
|
| usedNameOffsets: nameRelations.map((r) => r.offset).toList());
|
| }
|
|
|
| void defineName(String name, IndexNameKind kind, int offset) {
|
| - int nameId = pkg._getStringId(name);
|
| - definedNames.add(new _DefinedNameInfo(nameId, kind, offset));
|
| + _StringInfo nameInfo = pkg._getStringInfo(name);
|
| + definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset));
|
| }
|
| }
|
|
|