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

Unified Diff: dart/sdk/lib/_internal/lib/js_mirrors.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 | « dart/sdk/lib/_internal/lib/js_helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/dart/sdk/lib/_internal/lib/js_mirrors.dart b/dart/sdk/lib/_internal/lib/js_mirrors.dart
index 1580da7fd9b29d12b252ac5f67f79ba95bbad1f3..caf285c6b56cbb071d7c98aa6e39c253aefb4776 100644
--- a/dart/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/dart/sdk/lib/_internal/lib/js_mirrors.dart
@@ -18,6 +18,7 @@ import 'dart:_js_helper' show
BoundClosure,
Closure,
JSInvocationMirror,
+ JsCache,
Null,
Primitives,
RuntimeError,
@@ -532,6 +533,7 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
final _jsConstructorOrInterceptor;
final String _fieldsDescriptor;
final List _fieldsMetadata;
+ final _jsConstructorCache = JsCache.allocate();
List _metadata;
JsClassMirror _superclass;
List<JsMethodMirror> _cachedMethods;
@@ -767,15 +769,20 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
if (namedArguments != null && !namedArguments.isEmpty) {
throw new UnsupportedError('Named arguments are not implemented.');
}
- JsMethodMirror mirror = constructors.values.firstWhere(
- (m) => m.constructorName == constructorName,
- orElse: () {
- // TODO(ahe): Pass namedArguments when NoSuchMethodError has been
- // fixed to use Symbol.
- // TODO(ahe): What receiver to use?
- throw new NoSuchMethodError(
- owner, n(constructorName), positionalArguments, null);
- });
+ JsMethodMirror mirror =
+ JsCache.fetch(_jsConstructorCache, n(constructorName));
+ if (mirror == null) {
+ mirror = constructors.values.firstWhere(
+ (m) => m.constructorName == constructorName,
+ orElse: () {
+ // TODO(ahe): Pass namedArguments when NoSuchMethodError has been
+ // fixed to use Symbol.
+ // TODO(ahe): What receiver to use?
+ throw new NoSuchMethodError(
+ owner, n(constructorName), positionalArguments, null);
+ });
+ JsCache.update(_jsConstructorCache, n(constructorName), mirror);
+ }
return reflect(mirror._invoke(positionalArguments, namedArguments));
}
« no previous file with comments | « dart/sdk/lib/_internal/lib/js_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698