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

Unified Diff: runtime/lib/object_patch.dart

Issue 18826007: Reland r24563 and r24564 with fixes cumbersome API leading to leaks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/object_patch.dart
===================================================================
--- runtime/lib/object_patch.dart (revision 24817)
+++ runtime/lib/object_patch.dart (working copy)
@@ -4,20 +4,26 @@
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
+ // Helpers used to implement hashCode. If a hashCode is used, we remember it
+ // in a weak table in the VM. A new hashCode value is calculated using a
// number generator.
- static Expando _hashCodeExp = new Expando("Object.hashCode");
- static Random _hashCodeRnd = new Random();
+ static final _hashCodeRnd = new Random();
+ static _getHash(obj) native "Object_getHash";
+ static _setHash(obj, hash) native "Object_setHash";
+
/* patch */ int get hashCode {
if (this == null) {
return 2011; // The year Dart was announced and a prime.
}
- var result = _hashCodeExp[this];
- if (result == null) {
- result = _hashCodeRnd.nextInt(0x40000000); // Stay in Smi range.
- _hashCodeExp[this] = result;
+ var result = _getHash(this);
+ if (result == 0) {
+ // We want the hash to be a Smi value greater than 0.
+ result = _hashCodeRnd.nextInt(0x40000000);
+ while (result == 0) {
+ result = _hashCodeRnd.nextInt(0x40000000);
+ }
+ _setHash(this, result);
}
return result;
}
« no previous file with comments | « runtime/lib/object.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698