| 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 // using an Expando object. A new hashCode value is calculated using a Random | 8 // using an Expando object. A new hashCode value is calculated using a Random |
| 9 // number generator. | 9 // number generator. |
| 10 static Expando _hashCodeExp = new Expando("Object.hashCode"); | 10 static Expando _hashCodeExp = new Expando("Object.hashCode"); |
| 11 static Random _hashCodeRnd = new Random(); | 11 static Random _hashCodeRnd = new Random(); |
| 12 | 12 |
| 13 /* patch */ int get hashCode { | 13 /* patch */ int get hashCode { |
| 14 if (this == null) { |
| 15 return 2011; // The year Dart was announced and a prime. |
| 16 } |
| 14 var result = _hashCodeExp[this]; | 17 var result = _hashCodeExp[this]; |
| 15 if (result == null) { | 18 if (result == null) { |
| 16 result = _hashCodeRnd.nextInt(0x40000000); // Stay in Smi range. | 19 result = _hashCodeRnd.nextInt(0x40000000); // Stay in Smi range. |
| 17 _hashCodeExp[this] = result; | 20 _hashCodeExp[this] = result; |
| 18 } | 21 } |
| 19 return result; | 22 return result; |
| 20 } | 23 } |
| 21 | 24 |
| 22 /* patch */ String toString() native "Object_toString"; | 25 /* patch */ String toString() native "Object_toString"; |
| 23 // A statically dispatched version of Object.toString. | 26 // A statically dispatched version of Object.toString. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 // Call this function instead of inlining instanceof, thus collecting | 42 // Call this function instead of inlining instanceof, thus collecting |
| 40 // type feedback and reducing code size of unoptimized code. | 43 // type feedback and reducing code size of unoptimized code. |
| 41 _instanceOf(instantiator, | 44 _instanceOf(instantiator, |
| 42 instantiator_type_arguments, | 45 instantiator_type_arguments, |
| 43 type, | 46 type, |
| 44 bool negate) | 47 bool negate) |
| 45 native "Object_instanceOf"; | 48 native "Object_instanceOf"; |
| 46 | 49 |
| 47 /* patch */ Type get runtimeType native "Object_runtimeType"; | 50 /* patch */ Type get runtimeType native "Object_runtimeType"; |
| 48 } | 51 } |
| OLD | NEW |