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

Unified Diff: runtime/lib/object_patch.dart

Issue 24280003: Add Object.hashCodeOf to get the default hashCode of an object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | sdk/lib/_internal/lib/core_patch.dart » ('j') | sdk/lib/_internal/lib/core_patch.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+ // 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) {
+ 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;
}
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/core_patch.dart » ('j') | sdk/lib/_internal/lib/core_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698