Chromium Code Reviews| Index: runtime/lib/object_patch.dart |
| diff --git a/runtime/lib/object_patch.dart b/runtime/lib/object_patch.dart |
| index 2d42da7df44ebf90db1c20f3e6b0045f3bf5533a..df8073ee4742b872b6bdc15a3385641e740051af 100644 |
| --- a/runtime/lib/object_patch.dart |
| +++ b/runtime/lib/object_patch.dart |
| @@ -12,15 +12,27 @@ patch class Object { |
| static _getHash(obj) native "Object_getHash"; |
| static _setHash(obj, hash) native "Object_setHash"; |
| - /* patch */ int get hashCode { |
| - var result = _getHash(this); |
| + /* patch */ int get hashCode => _hashCodeOf(this); |
| + |
| + /* patch */ static int hashCodeOf(Object object) { |
| + // Num doesn't use identity hash for hashCode, and this method must be |
|
Ivan Posva
2013/09/24 06:22:11
I have read this comment several times and it stil
|
| + // consistent with `identical`. |
| + // Bool and Null overrides hashCode only in a patch. |
| + if (object is num || object is bool || object == null) { |
| + return object.hashCode; |
| + } |
| + return _hashCodeOf(object); |
| + } |
| + |
| + static int _hashCodeOf(Object object) { |
|
Ivan Posva
2013/09/24 06:22:11
Please leave this as a private dynamic method on O
|
| + var result = _getHash(object); |
| if (result == 0) { |
| // We want the hash to be a Smi value greater than 0. |
| result = _hashCodeRnd.nextInt(0x40000000); |
| while (result == 0) { |
| result = _hashCodeRnd.nextInt(0x40000000); |
| } |
| - _setHash(this, result); |
| + _setHash(object, result); |
| } |
| return result; |
| } |