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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 1997183002: Cache PrefixElement(s) in LibraryElementImpl. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 3732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 if (_unlinkedImport.isImplicit) { 3743 if (_unlinkedImport.isImplicit) {
3744 return -1; 3744 return -1;
3745 } 3745 }
3746 return _unlinkedImport.offset; 3746 return _unlinkedImport.offset;
3747 } 3747 }
3748 return super.nameOffset; 3748 return super.nameOffset;
3749 } 3749 }
3750 3750
3751 PrefixElement get prefix { 3751 PrefixElement get prefix {
3752 if (_unlinkedImport != null) { 3752 if (_unlinkedImport != null) {
3753 if (_unlinkedImport.prefixReference != 0) { 3753 if (_unlinkedImport.prefixReference != 0 && _prefix == null) {
3754 LibraryElementImpl library = enclosingElement as LibraryElementImpl; 3754 LibraryElementImpl library = enclosingElement as LibraryElementImpl;
3755 _prefix = new PrefixElementImpl.forSerialized(_unlinkedImport, library); 3755 _prefix = new PrefixElementImpl.forSerialized(_unlinkedImport, library);
3756 } 3756 }
3757 } 3757 }
3758 return _prefix; 3758 return _prefix;
3759 } 3759 }
3760 3760
3761 void set prefix(PrefixElement prefix) { 3761 void set prefix(PrefixElement prefix) {
3762 assert(_unlinkedImport == null); 3762 assert(_unlinkedImport == null);
3763 _prefix = prefix; 3763 _prefix = prefix;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 */ 3969 */
3970 Namespace _exportNamespace; 3970 Namespace _exportNamespace;
3971 3971
3972 /** 3972 /**
3973 * The public [Namespace] of this library, `null` if it has not been 3973 * The public [Namespace] of this library, `null` if it has not been
3974 * computed yet. 3974 * computed yet.
3975 */ 3975 */
3976 Namespace _publicNamespace; 3976 Namespace _publicNamespace;
3977 3977
3978 /** 3978 /**
3979 * The cached list of prefixes.
3980 */
3981 List<PrefixElement> _prefixes;
3982
3983 /**
3979 * Initialize a newly created library element in the given [context] to have 3984 * Initialize a newly created library element in the given [context] to have
3980 * the given [name] and [offset]. 3985 * the given [name] and [offset].
3981 */ 3986 */
3982 LibraryElementImpl(this.context, String name, int offset, this.nameLength) 3987 LibraryElementImpl(this.context, String name, int offset, this.nameLength)
3983 : resynthesizerContext = null, 3988 : resynthesizerContext = null,
3984 _unlinkedDefiningUnit = null, 3989 _unlinkedDefiningUnit = null,
3985 super(name, offset); 3990 super(name, offset);
3986 3991
3987 /** 3992 /**
3988 * Initialize a newly created library element in the given [context] to have 3993 * Initialize a newly created library element in the given [context] to have
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 * given list of [imports]. 4156 * given list of [imports].
4152 */ 4157 */
4153 void set imports(List<ImportElement> imports) { 4158 void set imports(List<ImportElement> imports) {
4154 for (ImportElement importElement in imports) { 4159 for (ImportElement importElement in imports) {
4155 (importElement as ImportElementImpl).enclosingElement = this; 4160 (importElement as ImportElementImpl).enclosingElement = this;
4156 PrefixElementImpl prefix = importElement.prefix as PrefixElementImpl; 4161 PrefixElementImpl prefix = importElement.prefix as PrefixElementImpl;
4157 if (prefix != null) { 4162 if (prefix != null) {
4158 prefix.enclosingElement = this; 4163 prefix.enclosingElement = this;
4159 } 4164 }
4160 } 4165 }
4161 this._imports = imports; 4166 this._imports = imports;
Brian Wilkerson 2016/05/21 15:22:05 We should flush _prefixes here.
scheglov 2016/05/22 01:53:38 Done.
4162 } 4167 }
4163 4168
4164 @override 4169 @override
4165 bool get isBrowserApplication => 4170 bool get isBrowserApplication =>
4166 entryPoint != null && isOrImportsBrowserLibrary; 4171 entryPoint != null && isOrImportsBrowserLibrary;
4167 4172
4168 @override 4173 @override
4169 bool get isDartAsync => name == "dart.async"; 4174 bool get isDartAsync => name == "dart.async";
4170 4175
4171 @override 4176 @override
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
4324 for (CompilationUnitElement compilationUnit in parts) { 4329 for (CompilationUnitElement compilationUnit in parts) {
4325 assert((compilationUnit as CompilationUnitElementImpl).librarySource == 4330 assert((compilationUnit as CompilationUnitElementImpl).librarySource ==
4326 source); 4331 source);
4327 (compilationUnit as CompilationUnitElementImpl).enclosingElement = this; 4332 (compilationUnit as CompilationUnitElementImpl).enclosingElement = this;
4328 } 4333 }
4329 this._parts = parts; 4334 this._parts = parts;
4330 } 4335 }
4331 4336
4332 @override 4337 @override
4333 List<PrefixElement> get prefixes { 4338 List<PrefixElement> get prefixes {
4334 HashSet<PrefixElement> prefixes = new HashSet<PrefixElement>(); 4339 if (_prefixes == null) {
4335 for (ImportElement element in _imports) { 4340 HashSet<PrefixElement> prefixes = new HashSet<PrefixElement>();
4336 PrefixElement prefix = element.prefix; 4341 for (ImportElement element in _imports) {
4337 if (prefix != null) { 4342 PrefixElement prefix = element.prefix;
4338 prefixes.add(prefix); 4343 if (prefix != null) {
4344 prefixes.add(prefix);
4345 }
4339 } 4346 }
4347 _prefixes = prefixes.toList();
4340 } 4348 }
4341 return new List.from(prefixes); 4349 return _prefixes;
4342 } 4350 }
4343 4351
4344 @override 4352 @override
4345 Namespace get publicNamespace { 4353 Namespace get publicNamespace {
4346 if (resynthesizerContext != null) { 4354 if (resynthesizerContext != null) {
4347 _publicNamespace ??= resynthesizerContext.buildPublicNamespace(); 4355 _publicNamespace ??= resynthesizerContext.buildPublicNamespace();
4348 } 4356 }
4349 return _publicNamespace; 4357 return _publicNamespace;
4350 } 4358 }
4351 4359
(...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after
6547 6555
6548 @override 6556 @override
6549 void visitElement(Element element) { 6557 void visitElement(Element element) {
6550 int offset = element.nameOffset; 6558 int offset = element.nameOffset;
6551 if (offset != -1) { 6559 if (offset != -1) {
6552 map[offset] = element; 6560 map[offset] = element;
6553 } 6561 }
6554 super.visitElement(element); 6562 super.visitElement(element);
6555 } 6563 }
6556 } 6564 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698