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 patch class Object { | 5 patch class Object { |
6 | 6 |
7 // The VM has its own implementation of equals. | 7 // The VM has its own implementation of equals. |
8 bool operator ==(other) native "Object_equals"; | 8 bool operator ==(other) native "Object_equals"; |
9 | 9 |
10 // Helpers used to implement hashCode. If a hashCode is used, we remember it | 10 // Helpers used to implement hashCode. If a hashCode is used, we remember it |
11 // in a weak table in the VM. A new hashCode value is calculated using a | 11 // in a weak table in the VM. A new hashCode value is calculated using a |
12 // number generator. | 12 // number generator. |
13 static final _hashCodeRnd = new Random(); | 13 static final _hashCodeRnd = new Random(); |
14 | 14 |
15 static _getHash(obj) native "Object_getHash"; | 15 static _getHash(obj) native "Object_getHash"; |
16 static _setHash(obj, hash) native "Object_setHash"; | 16 static _setHash(obj, hash) native "Object_setHash"; |
17 | 17 |
18 /* patch */ int get hashCode => _identityHashCode; | 18 // Shared static implentation for hashCode and _identityHashCode. |
19 | 19 static int _objectHashCode(obj) { |
20 int get _identityHashCode { | 20 var result = _getHash(obj); |
21 var result = _getHash(this); | |
22 if (result == 0) { | 21 if (result == 0) { |
23 // We want the hash to be a Smi value greater than 0. | 22 // We want the hash to be a Smi value greater than 0. |
24 result = _hashCodeRnd.nextInt(0x40000000); | 23 result = _hashCodeRnd.nextInt(0x40000000); |
25 while (result == 0) { | 24 while (result == 0) { |
26 result = _hashCodeRnd.nextInt(0x40000000); | 25 result = _hashCodeRnd.nextInt(0x40000000); |
27 } | 26 } |
28 _setHash(this, result); | 27 _setHash(obj, result); |
29 } | 28 } |
30 return result; | 29 return result; |
31 } | 30 } |
32 | 31 |
| 32 /* patch */ int get hashCode => _objectHashCode(this); |
| 33 int get _identityHashCode => _objectHashCode(this); |
| 34 |
33 /* patch */ String toString() native "Object_toString"; | 35 /* patch */ String toString() native "Object_toString"; |
34 // A statically dispatched version of Object.toString. | 36 // A statically dispatched version of Object.toString. |
35 static String _toString(obj) native "Object_toString"; | 37 static String _toString(obj) native "Object_toString"; |
36 | 38 |
37 _noSuchMethod(bool isMethod, | 39 _noSuchMethod(bool isMethod, |
38 String memberName, | 40 String memberName, |
39 int type, | 41 int type, |
40 List arguments, | 42 List arguments, |
41 Map<String, dynamic> namedArguments) | 43 Map<String, dynamic> namedArguments) |
42 native "Object_noSuchMethod"; | 44 native "Object_noSuchMethod"; |
(...skipping 24 matching lines...) Expand all Loading... |
67 _as(instantiator_type_arguments, type) native "Object_as"; | 69 _as(instantiator_type_arguments, type) native "Object_as"; |
68 | 70 |
69 static _symbolMapToStringMap(Map<Symbol, dynamic> map) { | 71 static _symbolMapToStringMap(Map<Symbol, dynamic> map) { |
70 var result = new Map<String, dynamic>(); | 72 var result = new Map<String, dynamic>(); |
71 map.forEach((Symbol key, value) { | 73 map.forEach((Symbol key, value) { |
72 result[internal.Symbol.getName(key)] = value; | 74 result[internal.Symbol.getName(key)] = value; |
73 }); | 75 }); |
74 return result; | 76 return result; |
75 } | 77 } |
76 } | 78 } |
OLD | NEW |