Skip to content

Commit aea2fa1

Browse files
committed
Update Symbol.hashCode
New dart2js version avoids inefficient String.hashCode [email protected] Review URL: https://codereview.chromium.org/2040963005 .
1 parent 5fd9235 commit aea2fa1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

pkg/dev_compiler/lib/runtime/dart_sdk.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7687,8 +7687,12 @@ dart_library.library('dart_sdk', null, /* Imports */[
76877687
return _internal.Symbol.is(other) && this[_name] == other[_name];
76887688
}
76897689
get hashCode() {
7690+
let hash = this._hashCode;
7691+
if (hash != null) return hash;
76907692
let arbitraryPrime = 664597;
7691-
return 536870911 & arbitraryPrime * dart.notNull(dart.hashCode(this[_name]));
7693+
hash = 536870911 & arbitraryPrime * dart.notNull(dart.hashCode(this[_name]));
7694+
this._hashCode = hash;
7695+
return hash;
76927696
}
76937697
toString() {
76947698
return dart.str`Symbol("${this[_name]}")`;

pkg/dev_compiler/tool/input_sdk/lib/internal/symbol.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ class Symbol implements core.Symbol {
112112

113113
bool operator ==(Object other) => other is Symbol && _name == other._name;
114114

115-
int get hashCode {
116-
const arbitraryPrime = 664597;
117-
return 0x1fffffff & (arbitraryPrime * _name.hashCode);
118-
}
115+
external int get hashCode;
119116

120117
toString() => 'Symbol("$_name")';
121118

pkg/dev_compiler/tool/input_sdk/patch/internal_patch.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
import 'dart:_js_primitives' show printString;
66
import 'dart:_js_helper' show patch;
77
import 'dart:_interceptors' show JSArray;
8+
import 'dart:_foreign_helper' show JS;
89

910
@patch
1011
class Symbol implements core.Symbol {
1112
@patch
1213
const Symbol(String name)
1314
: this._name = name;
15+
16+
@patch
17+
int get hashCode {
18+
int hash = JS('int|Null', '#._hashCode', this);
19+
if (hash != null) return hash;
20+
const arbitraryPrime = 664597;
21+
hash = 0x1fffffff & (arbitraryPrime * _name.hashCode);
22+
JS('', '#._hashCode = #', this, hash);
23+
return hash;
24+
}
1425
}
1526

1627
@patch

0 commit comments

Comments
 (0)