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

Side by Side 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: Now top-level and called identityHashCode Created 7 years, 2 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
« no previous file with comments | « runtime/lib/null_patch.dart ('k') | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 patch class Object { 5 patch class Object {
6 6
7 // Helpers used to implement hashCode. If a hashCode is used, we remember it 7 // Helpers used to implement hashCode. If a hashCode is used, we remember it
8 // in a weak table in the VM. A new hashCode value is calculated using a 8 // in a weak table in the VM. A new hashCode value is calculated using a
9 // number generator. 9 // number generator.
10 static final _hashCodeRnd = new Random(); 10 static final _hashCodeRnd = new Random();
11 11
12 static _getHash(obj) native "Object_getHash"; 12 static _getHash(obj) native "Object_getHash";
13 static _setHash(obj, hash) native "Object_setHash"; 13 static _setHash(obj, hash) native "Object_setHash";
14 14
15 /* patch */ int get hashCode { 15 /* patch */ int get hashCode => _identityHashCode;
16
17 int get _identityHashCode {
16 var result = _getHash(this); 18 var result = _getHash(this);
17 if (result == 0) { 19 if (result == 0) {
18 // We want the hash to be a Smi value greater than 0. 20 // We want the hash to be a Smi value greater than 0.
19 result = _hashCodeRnd.nextInt(0x40000000); 21 result = _hashCodeRnd.nextInt(0x40000000);
20 while (result == 0) { 22 while (result == 0) {
21 result = _hashCodeRnd.nextInt(0x40000000); 23 result = _hashCodeRnd.nextInt(0x40000000);
22 } 24 }
23 _setHash(this, result); 25 _setHash(this, result);
24 } 26 }
25 return result; 27 return result;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }); 67 });
66 return result; 68 return result;
67 } 69 }
68 70
69 int get _cid native "Object_cid"; 71 int get _cid native "Object_cid";
70 72
71 _leftShiftWithMask32(count, mask) { 73 _leftShiftWithMask32(count, mask) {
72 return (this << count) & mask; 74 return (this << count) & mask;
73 } 75 }
74 } 76 }
OLDNEW
« no previous file with comments | « runtime/lib/null_patch.dart ('k') | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698