mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-22 10:49:24 +08:00
perf($parse): optimize filter implementation
- generate less garbage - optimize argument collection - use call instead of apply for no arg case (2x boost)
This commit is contained in:
@@ -550,19 +550,31 @@ Parser.prototype = {
|
||||
filter: function() {
|
||||
var token = this.expect();
|
||||
var fn = this.$filter(token.text);
|
||||
var argsFn = [];
|
||||
while(this.expect(':')) {
|
||||
argsFn.push(this.expression());
|
||||
}
|
||||
return valueFn(fnInvoke);
|
||||
var argsFn;
|
||||
var args;
|
||||
|
||||
function fnInvoke(self, locals, input) {
|
||||
var args = [input];
|
||||
for (var i = 0; i < argsFn.length; i++) {
|
||||
args.push(argsFn[i](self, locals));
|
||||
if (this.peek(':')) {
|
||||
argsFn = [];
|
||||
args = []; // we can safely reuse the array
|
||||
while (this.expect(':')) {
|
||||
argsFn.push(this.expression());
|
||||
}
|
||||
return fn.apply(self, args);
|
||||
}
|
||||
|
||||
return valueFn(function $parseFilter(self, locals, input) {
|
||||
if (args) {
|
||||
args[0] = input;
|
||||
|
||||
var i = argsFn.length;
|
||||
while (i--) {
|
||||
args[i + 1] = argsFn[i](self, locals);
|
||||
}
|
||||
|
||||
return fn.apply(self, args);
|
||||
}
|
||||
|
||||
return fn.call(self, input);
|
||||
});
|
||||
},
|
||||
|
||||
expression: function() {
|
||||
|
||||
Reference in New Issue
Block a user