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

Unified Diff: third_party/pkg/angular/lib/core/parser/eval_calls.dart

Issue 256553002: Revert "Update all Angular libs (run update_all.sh)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
Index: third_party/pkg/angular/lib/core/parser/eval_calls.dart
diff --git a/third_party/pkg/angular/lib/core/parser/eval_calls.dart b/third_party/pkg/angular/lib/core/parser/eval_calls.dart
index 7ed2d143b0cb88384594e71718a154c6fa432a6a..c7c152a6a966bd14c049994fd6ce5d1e60cfac37 100644
--- a/third_party/pkg/angular/lib/core/parser/eval_calls.dart
+++ b/third_party/pkg/angular/lib/core/parser/eval_calls.dart
@@ -1,80 +1,125 @@
library angular.core.parser.eval_calls;
-import 'package:angular/core/parser/parser.dart';
+import 'dart:mirrors';
import 'package:angular/core/parser/syntax.dart' as syntax;
import 'package:angular/core/parser/utils.dart';
-import 'package:angular/core/module_internal.dart';
+import 'package:angular/core/module.dart';
+class CallScope extends syntax.CallScope with CallReflective {
+ final Symbol symbol;
+ CallScope(name, arguments)
+ : super(name, arguments)
+ , symbol = newSymbol(name);
+ eval(scope, [FilterMap filters]) => _eval(scope, scope);
+}
-class CallScope extends syntax.CallScope {
- final MethodClosure methodClosure;
- CallScope(name, this.methodClosure, arguments)
- : super(name, arguments);
+class CallMember extends syntax.CallMember with CallReflective {
+ final Symbol symbol;
+ CallMember(object, name, arguments)
+ : super(object, name, arguments)
+ , symbol = newSymbol(name);
+ eval(scope, [FilterMap filters]) => _eval(scope, object.eval(scope, filters));
+}
- eval(scope, [FormatterMap formatters]) {
- var positionals = arguments.positionals;
- var posArgs = new List(positionals.length);
- for(var i = 0; i < positionals.length; i++) {
- posArgs[i] = positionals[i].eval(scope, formatters);
- }
- var namedArgs = {};
- arguments.named.forEach((name, Expression exp) {
- namedArgs[name] = exp.eval(scope, formatters);
- });
- if (methodClosure == null) {
- _throwUndefinedFunction(name);
- }
- return methodClosure(scope, posArgs, namedArgs);
- }
+class CallScopeFast0 extends syntax.CallScope with CallFast {
+ final Function function;
+ CallScopeFast0(name, arguments, this.function) : super(name, arguments);
+ eval(scope, [FilterMap filters]) => _evaluate0(scope);
}
-class CallMember extends syntax.CallMember {
- final MethodClosure methodClosure;
- CallMember(object, this.methodClosure, name, arguments)
- : super(object, name, arguments)
- {
- if (methodClosure == null) {
- _throwUndefinedFunction(name);
+class CallScopeFast1 extends syntax.CallScope with CallFast {
+ final Function function;
+ CallScopeFast1(name, arguments, this.function) : super(name, arguments);
+ eval(scope, [FilterMap filters]) => _evaluate1(scope, arguments[0].eval(scope, filters));
+}
+
+class CallMemberFast0 extends syntax.CallMember with CallFast {
+ final Function function;
+ CallMemberFast0(object, name, arguments, this.function)
+ : super(object, name, arguments);
+ eval(scope, [FilterMap filters]) => _evaluate0(object.eval(scope, filters));
+}
+
+class CallMemberFast1 extends syntax.CallMember with CallFast {
+ final Function function;
+ CallMemberFast1(object, name, arguments, this.function)
+ : super(object, name, arguments);
+ eval(scope, [FilterMap filters]) => _evaluate1(object.eval(scope, filters),
+ arguments[0].eval(scope, filters));
+}
+
+class CallFunction extends syntax.CallFunction {
+ CallFunction(function, arguments) : super(function, arguments);
+ eval(scope, [FilterMap filters]) {
+ var function = this.function.eval(scope, filters);
+ if (function is !Function) {
+ throw new EvalError('${this.function} is not a function');
+ } else {
+ return relaxFnApply(function, evalList(scope, arguments, filters));
}
}
+}
+
+
+/**
+ * The [CallReflective] mixin is used to share code between call expressions
+ * where we need to use reflection to do the invocation. We optimize for the
+ * case where we invoke a method on the same holder repeatedly through caching.
+ */
+abstract class CallReflective {
+ static const int CACHED_MAP = 0;
+ static const int CACHED_FUNCTION = 1;
- eval(scope, [FormatterMap formatters]) {
- var positionals = arguments.positionals;
- var posArgs = new List(positionals.length);
- for(var i = 0; i < positionals.length; i++) {
- posArgs[i] = positionals[i].eval(scope, formatters);
+ int _cachedKind = 0;
+ var _cachedHolder = UNINITIALIZED;
+ var _cachedValue;
+
+ String get name;
+ Symbol get symbol;
+ List get arguments;
+
+ _eval(scope, holder) {
+ List arguments = evalList(scope, this.arguments);
+ if (!identical(holder, _cachedHolder)) {
+ return _evaluteUncached(holder, arguments);
}
- var namedArgs = {};
- arguments.named.forEach((name, Expression exp) {
- namedArgs[name] = exp.eval(scope, formatters);
- });
- return methodClosure(object.eval(scope, formatters), posArgs, namedArgs);
+ return (_cachedKind == CACHED_MAP)
+ ? relaxFnApply(ensureFunctionFromMap(holder, name), arguments)
+ : _cachedValue.invoke(symbol, arguments).reflectee;
}
-}
-class CallFunction extends syntax.CallFunction {
- final ClosureMap closureMap;
- CallFunction(function, this.closureMap, arguments) : super(function, arguments);
- eval(scope, [FormatterMap formatters]) {
- var function = this.function.eval(scope, formatters);
- if (function is! Function) {
- throw new EvalError('${this.function} is not a function');
+ _evaluteUncached(holder, arguments) {
+ _cachedHolder = holder;
+ if (holder is Map) {
+ _cachedKind = CACHED_MAP;
+ _cachedValue = null;
+ return relaxFnApply(ensureFunctionFromMap(holder, name), arguments);
+ } else if (symbol == null) {
+ _cachedHolder = UNINITIALIZED;
+ throw new EvalError("Undefined function $name");
} else {
- List positionals = evalList(scope, arguments.positionals, formatters);
- if (arguments.named.isNotEmpty) {
- var named = new Map<Symbol, dynamic>();
- arguments.named.forEach((String name, value) {
- named[closureMap.lookupSymbol(name)] = value.eval(scope, formatters);
- });
- return Function.apply(function, positionals, named);
- } else {
- return relaxFnApply(function, positionals);
- }
+ InstanceMirror mirror = reflect(holder);
+ _cachedKind = CACHED_FUNCTION;
+ _cachedValue = mirror;
+ return mirror.invoke(symbol, arguments).reflectee;
}
}
}
-_throwUndefinedFunction(name) {
- throw "Undefined function $name";
+/**
+ * The [CallFast] mixin is used to share code between call expressions
+ * where we have a pre-compiled helper function that we use to do the
+ * function invocation.
+ */
+abstract class CallFast {
+ String get name;
+ Function get function;
+
+ _evaluate0(holder) => (holder is Map)
+ ? ensureFunctionFromMap(holder, name)()
+ : function(holder);
+ _evaluate1(holder, a0) => (holder is Map)
+ ? ensureFunctionFromMap(holder, name)(a0)
+ : function(holder, a0);
}
« no previous file with comments | « third_party/pkg/angular/lib/core/parser/eval_access.dart ('k') | third_party/pkg/angular/lib/core/parser/lexer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698