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

Unified Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1714703002: Avoid redundant computation of enclosingElement in _getElementReferenceId (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/summarize_elements.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_elements.dart b/pkg/analyzer/lib/src/summary/summarize_elements.dart
index b89f885ab4126606376872af2106bb4ac2cf58dc..0dc271f864ab61544fc2ad4b57296835768cca27 100644
--- a/pkg/analyzer/lib/src/summary/summarize_elements.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_elements.dart
@@ -1016,8 +1016,9 @@ class _CompilationUnitSerializer {
return referenceMap.putIfAbsent(element, () {
LibraryElement dependentLibrary = librarySerializer.libraryElement;
int unit = 0;
+ Element enclosingElement;
if (element != null) {
- Element enclosingElement = element.enclosingElement;
+ enclosingElement = element.enclosingElement;
if (enclosingElement is CompilationUnitElement) {
dependentLibrary = enclosingElement.library;
unit = dependentLibrary.units.indexOf(enclosingElement);
@@ -1031,29 +1032,31 @@ class _CompilationUnitSerializer {
if (linked) {
linkedReference =
new LinkedReferenceBuilder(kind: kind, unit: unit, name: name);
- Element enclosing = element?.enclosingElement;
- if (enclosing != null && enclosing is! CompilationUnitElement) {
+ if (enclosingElement != null &&
+ enclosingElement is! CompilationUnitElement) {
linkedReference.containingReference =
- _getElementReferenceId(enclosing, linked: linked);
- if (enclosing is ClassElement) {
- linkedReference.numTypeParameters = enclosing.typeParameters.length;
- } else if (enclosing is ExecutableElement) {
+ _getElementReferenceId(enclosingElement, linked: linked);
+ if (enclosingElement is ClassElement) {
+ linkedReference.numTypeParameters =
+ enclosingElement.typeParameters.length;
+ } else if (enclosingElement is ExecutableElement) {
if (element is FunctionElement) {
- assert(enclosing.functions.contains(element));
- linkedReference.localIndex = enclosing.functions.indexOf(element);
+ assert(enclosingElement.functions.contains(element));
+ linkedReference.localIndex =
+ enclosingElement.functions.indexOf(element);
} else if (element is LocalVariableElement) {
- assert(enclosing.localVariables.contains(element));
+ assert(enclosingElement.localVariables.contains(element));
linkedReference.localIndex =
- enclosing.localVariables.indexOf(element);
+ enclosingElement.localVariables.indexOf(element);
} else {
throw new StateError(
'Unexpected enclosed element type: ${element.runtimeType}');
}
- } else if (enclosing is VariableElement) {
- assert(identical(enclosing.initializer, element));
+ } else if (enclosingElement is VariableElement) {
+ assert(identical(enclosingElement.initializer, element));
} else {
throw new StateError(
- 'Unexpected enclosing element type: ${enclosing.runtimeType}');
+ 'Unexpected enclosing element type: ${enclosingElement.runtimeType}');
}
}
index = linkedReferences.length;
« 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