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

Commit a1a9585

Browse files
committed
perf($parse): removing binaryFn and valueFn wrappers from filter expressions
1 parent fb39e32 commit a1a9585

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/ng/parse.js

+16-14
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() {
@@ -786,19 +789,19 @@ Parser.prototype = {
786789
},
787790

788791
object: function () {
789-
var keyValues = [];
792+
var keys = [], values = [];
790793
var allConstant = true;
791794
if (this.peekToken().text !== '}') {
792795
do {
793796
if (this.peek('}')) {
794797
// Support trailing commas per ES5.1.
795798
break;
796799
}
797-
var token = this.expect(),
798-
key = token.string || token.text;
800+
var token = this.expect();
801+
keys.push(token.string || token.text);
799802
this.consume(':');
800803
var value = this.expression();
801-
keyValues.push({key: key, value: value});
804+
values.push(value);
802805
if (!value.constant) {
803806
allConstant = false;
804807
}
@@ -808,9 +811,8 @@ Parser.prototype = {
808811

809812
return extend(function $parseObjectLiteral(self, locals) {
810813
var object = {};
811-
for (var i = 0, ii = keyValues.length; i < ii; i++) {
812-
var keyValue = keyValues[i];
813-
object[keyValue.key] = keyValue.value(self, locals);
814+
for (var i = 0, ii = values.length; i < ii; i++) {
815+
object[keys[i]] = values[i](self, locals);
814816
}
815817
return object;
816818
}, {

0 commit comments

Comments
 (0)