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

Unified Diff: runtime/lib/function.dart

Issue 2988493002: Reapply "Improve hashCode for closure objects" with fixes. (Closed)
Patch Set: Created 3 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/function.cc ('k') | runtime/vm/bootstrap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/function.dart
diff --git a/runtime/lib/function.dart b/runtime/lib/function.dart
index 7f0556de37369ccc5dda11d71eea2b0e25f49832..05a20a46bf3f28e47cbb5e79f7bac4238708d969 100644
--- a/runtime/lib/function.dart
+++ b/runtime/lib/function.dart
@@ -5,16 +5,23 @@
class _Closure implements Function {
bool operator ==(other) native "Closure_equals";
- int get hashCode native "Closure_hashCode";
+ int get hashCode {
+ if (_hash == null) {
+ _hash = _computeHash();
+ }
+ return _hash;
+ }
_Closure get call => this;
_Closure _clone() native "Closure_clone";
+ int _computeHash() native "Closure_computeHash";
+
// No instance fields should be declared before the following 4 fields whose
// offsets must be identical in Dart and C++.
- // The following 4 fields are declared both in raw_object.h (for direct access
+ // The following fields are declared both in raw_object.h (for direct access
// from C++ code) and also here so that the offset-to-field map used by
// deferred objects is properly initialized.
// Caution: These fields are not Dart instances, but VM objects. Their Dart
@@ -23,4 +30,13 @@ class _Closure implements Function {
var _function_type_arguments;
var _function;
var _context;
+
+ // Note: _Closure objects are created by VM "magically", without invoking
+ // constructor. So, _Closure default constructor is never compiled and
+ // detection of default-initialized fields is not performed.
+ // As a consequence, VM incorrectly assumes that _hash field is not
+ // nullable and may incorrectly remove 'if (_hash == null)' in get:hashCode.
+ // This initializer makes _hash field nullable even without constructor
+ // compilation.
+ var _hash = null;
}
« no previous file with comments | « runtime/lib/function.cc ('k') | runtime/vm/bootstrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698