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

Unified Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 207853002: Optimizations for hashCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/element.dart
diff --git a/pkg/analyzer/lib/src/generated/element.dart b/pkg/analyzer/lib/src/generated/element.dart
index 4cd44d6258f52c6f396aaa9d779ccbeb57174fa1..b54f1a9e8769513a8a413b8c147cba82d1e027be 100644
--- a/pkg/analyzer/lib/src/generated/element.dart
+++ b/pkg/analyzer/lib/src/generated/element.dart
@@ -3890,7 +3890,13 @@ abstract class ElementImpl implements Element {
// TODO: We might want to re-visit this optimization in the future.
// We cache the hash code value as this is a very frequently called method.
if (_cachedHashCode == 0) {
- _cachedHashCode = location.hashCode;
+ int hashIdentifier = identifier.hashCode;
+ Element enclosing = enclosingElement;
+ if (enclosing != null) {
+ _cachedHashCode = hashIdentifier + enclosing.hashCode;
+ } else {
+ _cachedHashCode = hashIdentifier;
+ }
}
return _cachedHashCode;
}
@@ -9674,6 +9680,8 @@ class TypeImpl_TypePair {
DartType _secondType;
+ int _cachedHashCode = 0;
+
TypeImpl_TypePair(DartType firstType, DartType secondType) {
this._firstType = firstType;
this._secondType = secondType;
@@ -9693,15 +9701,20 @@ class TypeImpl_TypePair {
@override
int get hashCode {
- int firstHashCode = 0;
- if (_firstType != null) {
- firstHashCode = _firstType.element == null ? 0 : _firstType.element.hashCode;
- }
- int secondHashCode = 0;
- if (_secondType != null) {
- secondHashCode = _secondType.element == null ? 0 : _secondType.element.hashCode;
+ if (_cachedHashCode == 0) {
+ int firstHashCode = 0;
+ if (_firstType != null) {
+ Element firstElement = _firstType.element;
+ firstHashCode = firstElement == null ? 0 : firstElement.hashCode;
+ }
+ int secondHashCode = 0;
+ if (_secondType != null) {
+ Element secondElement = _secondType.element;
+ secondHashCode = secondElement == null ? 0 : secondElement.hashCode;
+ }
+ _cachedHashCode = firstHashCode + secondHashCode;
}
- return firstHashCode + secondHashCode;
+ return _cachedHashCode;
}
}

Powered by Google App Engine
This is Rietveld 408576698