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

Side by Side 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 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element; 8 library engine.element;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 3872 matching lines...) Expand 10 before | Expand all | Expand 10 after
3883 } 3883 }
3884 3884
3885 @override 3885 @override
3886 CompilationUnit get unit => context.resolveCompilationUnit(source, library); 3886 CompilationUnit get unit => context.resolveCompilationUnit(source, library);
3887 3887
3888 @override 3888 @override
3889 int get hashCode { 3889 int get hashCode {
3890 // TODO: We might want to re-visit this optimization in the future. 3890 // TODO: We might want to re-visit this optimization in the future.
3891 // We cache the hash code value as this is a very frequently called method. 3891 // We cache the hash code value as this is a very frequently called method.
3892 if (_cachedHashCode == 0) { 3892 if (_cachedHashCode == 0) {
3893 _cachedHashCode = location.hashCode; 3893 int hashIdentifier = identifier.hashCode;
3894 Element enclosing = enclosingElement;
3895 if (enclosing != null) {
3896 _cachedHashCode = hashIdentifier + enclosing.hashCode;
3897 } else {
3898 _cachedHashCode = hashIdentifier;
3899 }
3894 } 3900 }
3895 return _cachedHashCode; 3901 return _cachedHashCode;
3896 } 3902 }
3897 3903
3898 @override 3904 @override
3899 bool isAccessibleIn(LibraryElement library) { 3905 bool isAccessibleIn(LibraryElement library) {
3900 if (Identifier.isPrivateName(_name)) { 3906 if (Identifier.isPrivateName(_name)) {
3901 return library == this.library; 3907 return library == this.library;
3902 } 3908 }
3903 return true; 3909 return true;
(...skipping 5763 matching lines...) Expand 10 before | Expand all | Expand 10 after
9667 bool internalIsMoreSpecificThan(DartType type, bool withDynamic, Set<TypeImpl_ TypePair> visitedTypePairs); 9673 bool internalIsMoreSpecificThan(DartType type, bool withDynamic, Set<TypeImpl_ TypePair> visitedTypePairs);
9668 9674
9669 bool internalIsSubtypeOf(DartType type, Set<TypeImpl_TypePair> visitedTypePair s); 9675 bool internalIsSubtypeOf(DartType type, Set<TypeImpl_TypePair> visitedTypePair s);
9670 } 9676 }
9671 9677
9672 class TypeImpl_TypePair { 9678 class TypeImpl_TypePair {
9673 DartType _firstType; 9679 DartType _firstType;
9674 9680
9675 DartType _secondType; 9681 DartType _secondType;
9676 9682
9683 int _cachedHashCode = 0;
9684
9677 TypeImpl_TypePair(DartType firstType, DartType secondType) { 9685 TypeImpl_TypePair(DartType firstType, DartType secondType) {
9678 this._firstType = firstType; 9686 this._firstType = firstType;
9679 this._secondType = secondType; 9687 this._secondType = secondType;
9680 } 9688 }
9681 9689
9682 @override 9690 @override
9683 bool operator ==(Object object) { 9691 bool operator ==(Object object) {
9684 if (identical(object, this)) { 9692 if (identical(object, this)) {
9685 return true; 9693 return true;
9686 } 9694 }
9687 if (object is TypeImpl_TypePair) { 9695 if (object is TypeImpl_TypePair) {
9688 TypeImpl_TypePair typePair = object; 9696 TypeImpl_TypePair typePair = object;
9689 return _firstType == typePair._firstType && _secondType != null && _second Type == typePair._secondType; 9697 return _firstType == typePair._firstType && _secondType != null && _second Type == typePair._secondType;
9690 } 9698 }
9691 return false; 9699 return false;
9692 } 9700 }
9693 9701
9694 @override 9702 @override
9695 int get hashCode { 9703 int get hashCode {
9696 int firstHashCode = 0; 9704 if (_cachedHashCode == 0) {
9697 if (_firstType != null) { 9705 int firstHashCode = 0;
9698 firstHashCode = _firstType.element == null ? 0 : _firstType.element.hashCo de; 9706 if (_firstType != null) {
9707 Element firstElement = _firstType.element;
9708 firstHashCode = firstElement == null ? 0 : firstElement.hashCode;
9709 }
9710 int secondHashCode = 0;
9711 if (_secondType != null) {
9712 Element secondElement = _secondType.element;
9713 secondHashCode = secondElement == null ? 0 : secondElement.hashCode;
9714 }
9715 _cachedHashCode = firstHashCode + secondHashCode;
9699 } 9716 }
9700 int secondHashCode = 0; 9717 return _cachedHashCode;
9701 if (_secondType != null) {
9702 secondHashCode = _secondType.element == null ? 0 : _secondType.element.has hCode;
9703 }
9704 return firstHashCode + secondHashCode;
9705 } 9718 }
9706 } 9719 }
9707 9720
9708 /** 9721 /**
9709 * Instances of the class `TypeParameterTypeImpl` defines the behavior of object s representing 9722 * Instances of the class `TypeParameterTypeImpl` defines the behavior of object s representing
9710 * the type introduced by a type parameter. 9723 * the type introduced by a type parameter.
9711 */ 9724 */
9712 class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType { 9725 class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
9713 /** 9726 /**
9714 * An empty array of type parameter types. 9727 * An empty array of type parameter types.
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
10448 } 10461 }
10449 10462
10450 /** 10463 /**
10451 * The interface `VoidType` defines the behavior of the unique object representi ng the type 10464 * The interface `VoidType` defines the behavior of the unique object representi ng the type
10452 * `void`. 10465 * `void`.
10453 */ 10466 */
10454 abstract class VoidType implements DartType { 10467 abstract class VoidType implements DartType {
10455 @override 10468 @override
10456 VoidType substitute2(List<DartType> argumentTypes, List<DartType> parameterTyp es); 10469 VoidType substitute2(List<DartType> argumentTypes, List<DartType> parameterTyp es);
10457 } 10470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698