| 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 // 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 { |
| 16 if (this == null) { | |
| 17 return 2011; // The year Dart was announced and a prime. | |
| 18 } | |
| 19 var result = _getHash(this); | 16 var result = _getHash(this); |
| 20 if (result == 0) { | 17 if (result == 0) { |
| 21 // We want the hash to be a Smi value greater than 0. | 18 // We want the hash to be a Smi value greater than 0. |
| 22 result = _hashCodeRnd.nextInt(0x40000000); | 19 result = _hashCodeRnd.nextInt(0x40000000); |
| 23 while (result == 0) { | 20 while (result == 0) { |
| 24 result = _hashCodeRnd.nextInt(0x40000000); | 21 result = _hashCodeRnd.nextInt(0x40000000); |
| 25 } | 22 } |
| 26 _setHash(this, result); | 23 _setHash(this, result); |
| 27 } | 24 } |
| 28 return result; | 25 return result; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 }); | 65 }); |
| 69 return result; | 66 return result; |
| 70 } | 67 } |
| 71 | 68 |
| 72 int get _cid native "Object_cid"; | 69 int get _cid native "Object_cid"; |
| 73 | 70 |
| 74 _leftShiftWithMask32(count, mask) { | 71 _leftShiftWithMask32(count, mask) { |
| 75 return (this << count) & mask; | 72 return (this << count) & mask; |
| 76 } | 73 } |
| 77 } | 74 } |
| OLD | NEW |