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

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 144383007: Optimize getField by caching a closure generated from eval. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: TODO weak Created 6 years, 10 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/mirrors.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/mirrors_impl.dart
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart
index 310c9f7b48b997589ce658ab2ed42fdff2009365..baca1e56fe32d48e0624e3d8cab9b4ce98a15dda 100644
--- a/runtime/lib/mirrors_impl.dart
+++ b/runtime/lib/mirrors_impl.dart
@@ -332,6 +332,52 @@ class _LocalInstanceMirror extends _LocalObjectMirror
return new _InvocationTrampoline(this, selector);
}
+ // TODO(16539): Make these weak.
kasperl 2014/02/05 08:34:26 I guess there's no need for complex weak handling
rmacnak 2014/02/05 18:53:41 Soft would do as well. Though I wonder if this wou
+ static Map _getFieldClosures = new HashMap();
+ static Map _setFieldClosures = new HashMap();
+
+ InstanceMirror getField(Symbol memberName) {
+ var f = _getFieldClosures[_n(memberName)];
+ if (f == null) {
kasperl 2014/02/05 08:32:13 Consider splitting this method in two so it become
+ var unwrapped = _n(memberName);
kasperl 2014/02/05 08:32:13 Cache _n(memberName) in a local?
kasperl 2014/02/05 09:05:40 I guess what I meant was: Use unwrapped consistent
+ var at_pos = unwrapped.indexOf('@');
kasperl 2014/02/05 08:32:13 Follow Dart coding style: at_pos -> atPosition or
+ if (at_pos == -1) {
+ // Public symbol.
+ f = _eval('(x) => x.$unwrapped', null);
+ } else {
+ // Private symbol.
+ var withoutKey = unwrapped.substring(0, at_pos);
+ var privateKey = unwrapped.substring(at_pos);
+ f = _eval('(x) => x.$withoutKey', privateKey);
+ }
+ _getFieldClosures[_n(memberName)] = f;
+ }
+ return reflect(f(_reflectee));
+ }
+
+ InstanceMirror setField(Symbol memberName, arg) {
+ var f = _setFieldClosures[_n(memberName)];
kasperl 2014/02/05 08:32:13 Cache _n(memberName) in a local?
+ if (f == null) {
+ var unwrapped = _n(memberName);
+ var at_pos = unwrapped.indexOf('@');
kasperl 2014/02/05 08:32:13 Follow Dart coding style: at_pos -> atPosition or
+ if (at_pos == -1) {
+ // Public symbol.
+ f = _eval('(x, v) => x.$unwrapped = v', null);
+ } else {
+ // Private symbol.
+ var withoutKey = unwrapped.substring(0, at_pos);
+ var privateKey = unwrapped.substring(at_pos);
+ f = _eval('(x, v) => x.$withoutKey = v', privateKey);
+ }
+ _setFieldClosures[_n(memberName)] = f;
+ }
+ f(_reflectee, arg);
+ return reflect(arg);
+ }
+
+ static _eval(expression, privateKey)
+ native "Mirrors_evalInLibraryWithPrivateKey";
+
// Override to include the receiver in the arguments.
InstanceMirror invoke(Symbol memberName,
List positionalArguments,
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698