Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: pkg/analysis_server/lib/src/services/index/index_contributor.dart

Issue 971833003: Optimize top-level element declarations search. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 services.src.index.index_contributor; 5 library services.src.index.index_contributor;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import 'package:analysis_server/src/services/correction/namespace.dart'; 9 import 'package:analysis_server/src/services/correction/namespace.dart';
10 import 'package:analysis_server/src/services/index/index.dart'; 10 import 'package:analysis_server/src/services/index/index.dart';
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 visitBinaryExpression(BinaryExpression node) { 124 visitBinaryExpression(BinaryExpression node) {
125 _recordOperatorReference(node.operator, node.bestElement); 125 _recordOperatorReference(node.operator, node.bestElement);
126 super.visitBinaryExpression(node); 126 super.visitBinaryExpression(node);
127 } 127 }
128 128
129 @override 129 @override
130 visitClassDeclaration(ClassDeclaration node) { 130 visitClassDeclaration(ClassDeclaration node) {
131 ClassElement element = node.element; 131 ClassElement element = node.element;
132 enterScope(element); 132 enterScope(element);
133 try { 133 try {
134 _recordElementDefinition(element); 134 _recordTopLevelElementDefinition(element);
135 { 135 {
136 ExtendsClause extendsClause = node.extendsClause; 136 ExtendsClause extendsClause = node.extendsClause;
137 if (extendsClause != null) { 137 if (extendsClause != null) {
138 TypeName superclassNode = extendsClause.superclass; 138 TypeName superclassNode = extendsClause.superclass;
139 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); 139 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY);
140 } else { 140 } else {
141 InterfaceType superType = element.supertype; 141 InterfaceType superType = element.supertype;
142 if (superType != null) { 142 if (superType != null) {
143 ClassElement objectElement = superType.element; 143 ClassElement objectElement = superType.element;
144 recordRelationship( 144 recordRelationship(
(...skipping 23 matching lines...) Expand all
168 } finally { 168 } finally {
169 _exitScope(); 169 _exitScope();
170 } 170 }
171 } 171 }
172 172
173 @override 173 @override
174 visitClassTypeAlias(ClassTypeAlias node) { 174 visitClassTypeAlias(ClassTypeAlias node) {
175 ClassElement element = node.element; 175 ClassElement element = node.element;
176 enterScope(element); 176 enterScope(element);
177 try { 177 try {
178 _recordElementDefinition(element); 178 _recordTopLevelElementDefinition(element);
179 { 179 {
180 TypeName superclassNode = node.superclass; 180 TypeName superclassNode = node.superclass;
181 if (superclassNode != null) { 181 if (superclassNode != null) {
182 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); 182 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY);
183 } 183 }
184 } 184 }
185 { 185 {
186 WithClause withClause = node.withClause; 186 WithClause withClause = node.withClause;
187 if (withClause != null) { 187 if (withClause != null) {
188 for (TypeName mixinNode in withClause.mixinTypes) { 188 for (TypeName mixinNode in withClause.mixinTypes) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } finally { 279 } finally {
280 _exitScope(); 280 _exitScope();
281 } 281 }
282 } 282 }
283 283
284 @override 284 @override
285 visitEnumDeclaration(EnumDeclaration node) { 285 visitEnumDeclaration(EnumDeclaration node) {
286 ClassElement element = node.element; 286 ClassElement element = node.element;
287 enterScope(element); 287 enterScope(element);
288 try { 288 try {
289 _recordElementDefinition(element); 289 _recordTopLevelElementDefinition(element);
290 super.visitEnumDeclaration(node); 290 super.visitEnumDeclaration(node);
291 } finally { 291 } finally {
292 _exitScope(); 292 _exitScope();
293 } 293 }
294 } 294 }
295 295
296 @override 296 @override
297 visitExportDirective(ExportDirective node) { 297 visitExportDirective(ExportDirective node) {
298 ExportElement element = node.element; 298 ExportElement element = node.element;
299 if (element != null) { 299 if (element != null) {
(...skipping 10 matching lines...) Expand all
310 try { 310 try {
311 super.visitFormalParameter(node); 311 super.visitFormalParameter(node);
312 } finally { 312 } finally {
313 _exitScope(); 313 _exitScope();
314 } 314 }
315 } 315 }
316 316
317 @override 317 @override
318 visitFunctionDeclaration(FunctionDeclaration node) { 318 visitFunctionDeclaration(FunctionDeclaration node) {
319 Element element = node.element; 319 Element element = node.element;
320 _recordElementDefinition(element); 320 _recordTopLevelElementDefinition(element);
321 enterScope(element); 321 enterScope(element);
322 try { 322 try {
323 super.visitFunctionDeclaration(node); 323 super.visitFunctionDeclaration(node);
324 } finally { 324 } finally {
325 _exitScope(); 325 _exitScope();
326 } 326 }
327 } 327 }
328 328
329 @override 329 @override
330 visitFunctionTypeAlias(FunctionTypeAlias node) { 330 visitFunctionTypeAlias(FunctionTypeAlias node) {
331 Element element = node.element; 331 Element element = node.element;
332 _recordElementDefinition(element); 332 _recordTopLevelElementDefinition(element);
333 super.visitFunctionTypeAlias(node); 333 super.visitFunctionTypeAlias(node);
334 } 334 }
335 335
336 @override 336 @override
337 visitImportDirective(ImportDirective node) { 337 visitImportDirective(ImportDirective node) {
338 ImportElement element = node.element; 338 ImportElement element = node.element;
339 if (element != null) { 339 if (element != null) {
340 LibraryElement impLibrary = element.importedLibrary; 340 LibraryElement impLibrary = element.importedLibrary;
341 _recordLibraryReference(node, impLibrary); 341 _recordLibraryReference(node, impLibrary);
342 } 342 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); 527 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location);
528 super.visitSuperConstructorInvocation(node); 528 super.visitSuperConstructorInvocation(node);
529 } 529 }
530 530
531 @override 531 @override
532 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 532 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
533 VariableDeclarationList variables = node.variables; 533 VariableDeclarationList variables = node.variables;
534 for (VariableDeclaration variableDeclaration in variables.variables) { 534 for (VariableDeclaration variableDeclaration in variables.variables) {
535 Element element = variableDeclaration.element; 535 Element element = variableDeclaration.element;
536 _recordElementDefinition(element); 536 _recordTopLevelElementDefinition(element);
537 } 537 }
538 super.visitTopLevelVariableDeclaration(node); 538 super.visitTopLevelVariableDeclaration(node);
539 } 539 }
540 540
541 @override 541 @override
542 visitTypeParameter(TypeParameter node) { 542 visitTypeParameter(TypeParameter node) {
543 TypeParameterElement element = node.element; 543 TypeParameterElement element = node.element;
544 enterScope(element); 544 enterScope(element);
545 try { 545 try {
546 super.visitTypeParameter(node); 546 super.visitTypeParameter(node);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 target.staticElement is PrefixElement) { 670 target.staticElement is PrefixElement) {
671 return false; 671 return false;
672 } 672 }
673 return target != null; 673 return target != null;
674 } 674 }
675 } 675 }
676 return false; 676 return false;
677 } 677 }
678 678
679 /** 679 /**
680 * Records the [Element] definition in the library and universe.
681 */
682 void _recordElementDefinition(Element element) {
683 Location location = createLocation(element);
684 Relationship relationship = IndexConstants.DEFINES;
685 recordRelationship(_libraryElement, relationship, location);
686 recordRelationship(UniverseElement.INSTANCE, relationship, location);
687 }
688
689 /**
690 * Records [ImportElement] reference if given [SimpleIdentifier] references so me 680 * Records [ImportElement] reference if given [SimpleIdentifier] references so me
691 * top-level element and not qualified with import prefix. 681 * top-level element and not qualified with import prefix.
692 */ 682 */
693 void _recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { 683 void _recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) {
694 if (_isIdentifierInImportCombinator(node)) { 684 if (_isIdentifierInImportCombinator(node)) {
695 return; 685 return;
696 } 686 }
697 if (_isIdentifierInPrefixedIdentifier(node)) { 687 if (_isIdentifierInPrefixedIdentifier(node)) {
698 return; 688 return;
699 } 689 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 Element superElement = superName.staticElement; 767 Element superElement = superName.staticElement;
778 recordRelationship( 768 recordRelationship(
779 superElement, 769 superElement,
780 relationship, 770 relationship,
781 _createLocationForNode(superNode)); 771 _createLocationForNode(superNode));
782 } 772 }
783 } 773 }
784 } 774 }
785 775
786 /** 776 /**
777 * Records the [Element] definition in the library and universe.
778 */
779 void _recordTopLevelElementDefinition(Element element) {
780 Location location = createLocation(element);
781 recordRelationship(_libraryElement, IndexConstants.DEFINES, location);
782 _store.recordTopDeclaration(element);
783 }
784
785 /**
787 * Creates a [Location] representing declaration of the [Element]. 786 * Creates a [Location] representing declaration of the [Element].
788 */ 787 */
789 static Location createLocation(Element element) { 788 static Location createLocation(Element element) {
790 if (element != null) { 789 if (element != null) {
791 int offset = element.nameOffset; 790 int offset = element.nameOffset;
792 int length = element.displayName.length; 791 int length = element.displayName.length;
793 return new Location(element, offset, length); 792 return new Location(element, offset, length);
794 } 793 }
795 return null; 794 return null;
796 } 795 }
(...skipping 21 matching lines...) Expand all
818 } 817 }
819 818
820 /** 819 /**
821 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node ". 820 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node ".
822 */ 821 */
823 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { 822 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) {
824 AstNode parent = node.parent; 823 AstNode parent = node.parent;
825 return parent is PrefixedIdentifier && parent.identifier == node; 824 return parent is PrefixedIdentifier && parent.identifier == node;
826 } 825 }
827 } 826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698