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

Unified Diff: dart/sdk/lib/_internal/lib/js_helper.dart

Issue 22934004: Improve performance of ClassMirror.newInstance. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use JsCache helper class as suggested by Nicolas. Created 7 years, 4 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 | « no previous file | dart/sdk/lib/_internal/lib/js_mirrors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/sdk/lib/_internal/lib/js_helper.dart
diff --git a/dart/sdk/lib/_internal/lib/js_helper.dart b/dart/sdk/lib/_internal/lib/js_helper.dart
index 65ed469c690e8837f2bbf0f074aa441948f63c94..f34c02ad5c3f375a8b49529d68d6ee952ffa9a69 100644
--- a/dart/sdk/lib/_internal/lib/js_helper.dart
+++ b/dart/sdk/lib/_internal/lib/js_helper.dart
@@ -660,6 +660,26 @@ class Primitives {
}
}
+/// Helper class for allocating and using JS object literals as caches.
+class JsCache {
+ /// Returns a JavaScript object suitable for use as a cache.
+ static allocate() {
+ var result = JS('=Object', '{x:0}');
+ // Deleting a property makes V8 assume that it shouldn't create a hidden
+ // class for [result] and map transitions. Although these map transitions
+ // pay off if there are many cache hits for the same keys, it becomes
+ // really slow when there aren't many repeated hits.
+ JS('void', 'delete #.x', result);
+ return result;
+ }
+
+ static fetch(cache, String key) => JS('', '#[#]', cache, key);
+
+ static void update(cache, String key, value) {
+ return JS('void', '#[#] = #', cache, key, value);
+ }
+}
+
/**
* Called by generated code to throw an illegal-argument exception,
* for example, if a non-integer index is given to an optimized
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/lib/js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698