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

Unified Diff: runtime/lib/object_patch.dart

Issue 10956026: - Add definition of "int hashCode()" to Object. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/object_patch.dart
===================================================================
--- runtime/lib/object_patch.dart (revision 12648)
+++ runtime/lib/object_patch.dart (working copy)
@@ -3,6 +3,22 @@
// BSD-style license that can be found in the LICENSE file.
patch class Object {
+
+ // Helpers used to implement hashCode. If a hashCode is used we remember it
+ // using an Expando object. A new hashCode value is calculated using a Random
+ // number generator.
+ static Expando _hashCodeExp = new Expando("Object.hashCode");
+ static Random _hashCodeRnd = new Random();
+
+ /* patch */ int hashCode() {
+ var result = _hashCodeExp[this];
+ if (result == null) {
+ result = _hashCodeRnd.nextInt(0x40000000); // Stay in Smi range.
+ _hashCodeExp[this] = result;
+ }
+ return result;
+ }
+
/* patch */ String toString() => _toString(this);
/* patch */ void noSuchMethod(String functionName, List args) {

Powered by Google App Engine
This is Rietveld 408576698