OLD | NEW |
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 int _getHash(obj) native "Object_getHash"; | 5 int _getHash(obj) native "Object_getHash"; |
6 int _setHash(obj, hash) native "Object_setHash"; | 6 int _setHash(obj, hash) native "Object_setHash"; |
7 | 7 |
8 @patch | 8 @patch |
9 class Object { | 9 class Object { |
10 // The VM has its own implementation of equals. | 10 // The VM has its own implementation of equals. |
11 @patch | 11 @patch |
12 bool operator ==(other) native "Object_equals"; | 12 bool operator ==(other) native "Object_equals"; |
13 | 13 |
14 // Helpers used to implement hashCode. If a hashCode is used, we remember it | 14 // Helpers used to implement hashCode. If a hashCode is used, we remember it |
15 // in a weak table in the VM (32 bit) or in the header of the object (64 | 15 // in a weak table in the VM (32 bit) or in the header of the object (64 |
16 // bit). A new hashCode value is calculated using a random number generator. | 16 // bit). A new hashCode value is calculated using a random number generator. |
17 static final _hashCodeRnd = new Random(); | 17 static final _hashCodeRnd = new Random(); |
18 | 18 |
19 // Shared static implentation for hashCode and _identityHashCode. | 19 // Shared static implementation for hashCode and _identityHashCode. |
20 static int _objectHashCode(obj) { | 20 static int _objectHashCode(obj) { |
21 var result = _getHash(obj); | 21 var result = _getHash(obj); |
22 if (result == 0) { | 22 if (result == 0) { |
23 // We want the hash to be a Smi value greater than 0. | 23 // We want the hash to be a Smi value greater than 0. |
24 do { | 24 do { |
25 result = _hashCodeRnd.nextInt(0x40000000); | 25 result = _hashCodeRnd.nextInt(0x40000000); |
26 } while (result == 0); | 26 } while (result == 0); |
27 _setHash(obj, result); | 27 _setHash(obj, result); |
28 } | 28 } |
29 return result; | 29 return result; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 native "Object_as"; | 72 native "Object_as"; |
73 | 73 |
74 static _symbolMapToStringMap(Map<Symbol, dynamic> map) { | 74 static _symbolMapToStringMap(Map<Symbol, dynamic> map) { |
75 var result = new Map<String, dynamic>(); | 75 var result = new Map<String, dynamic>(); |
76 map.forEach((Symbol key, value) { | 76 map.forEach((Symbol key, value) { |
77 result[internal.Symbol.getName(key)] = value; | 77 result[internal.Symbol.getName(key)] = value; |
78 }); | 78 }); |
79 return result; | 79 return result; |
80 } | 80 } |
81 } | 81 } |
OLD | NEW |