Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 67919c8

Browse files
jbedardIgorMinar
authored andcommitted
perf($parse): removing binaryFn and valueFn wrappers from filter expressions
Improves parsed-expressions/filters benchmark by 15%.
1 parent 5cf1d89 commit 67919c8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/ng/parse.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ var OPERATORS = extend(createMap(), {
112112
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
113113
'%':function(self, locals, a,b){return a(self, locals)%b(self, locals);},
114114
'^':function(self, locals, a,b){return a(self, locals)^b(self, locals);},
115-
'=':noop,
116115
'===':function(self, locals, a, b){return a(self, locals)===b(self, locals);},
117116
'!==':function(self, locals, a, b){return a(self, locals)!==b(self, locals);},
118117
'==':function(self, locals, a,b){return a(self, locals)==b(self, locals);},
@@ -125,8 +124,11 @@ var OPERATORS = extend(createMap(), {
125124
'||':function(self, locals, a,b){return a(self, locals)||b(self, locals);},
126125
'&':function(self, locals, a,b){return a(self, locals)&b(self, locals);},
127126
// '|':function(self, locals, a,b){return a|b;},
128-
'|':function(self, locals, a,b){return b(self, locals)(self, locals, a(self, locals));},
129-
'!':function(self, locals, a){return !a(self, locals);}
127+
'!':function(self, locals, a){return !a(self, locals);},
128+
129+
//Tokenized as operators but parsed as assignment/filters
130+
'=':true,
131+
'|':true
130132
});
131133
/* jshint bitwise: true */
132134
var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};
@@ -537,12 +539,12 @@ Parser.prototype = {
537539
var left = this.expression();
538540
var token;
539541
while ((token = this.expect('|'))) {
540-
left = this.binaryFn(left, token.fn, this.filter());
542+
left = this.filter(left);
541543
}
542544
return left;
543545
},
544546

545-
filter: function() {
547+
filter: function(inputFn) {
546548
var token = this.expect();
547549
var fn = this.$filter(token.text);
548550
var argsFn;
@@ -556,7 +558,8 @@ Parser.prototype = {
556558
}
557559
}
558560

559-
return valueFn(function $parseFilter(self, locals, input) {
561+
return function $parseFilter(self, locals) {
562+
var input = inputFn(self, locals);
560563
if (args) {
561564
args[0] = input;
562565

@@ -569,7 +572,7 @@ Parser.prototype = {
569572
}
570573

571574
return fn(input);
572-
});
575+
};
573576
},
574577

575578
expression: function() {

0 commit comments

Comments
 (0)