Skip to content

Commit dd0b9e6

Browse files
committed
WIP: perf optimizations
avoid hasOwnProperty calls and more
1 parent 65caaaa commit dd0b9e6

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ function isPromiseLike(obj) {
575575

576576
function isPrimitive(value) {
577577
var valueType;
578-
return (value == null || (valueType = typeof value) === 'number' || valueType === 'string');
578+
return (value == null || (valueType = typeof value) === 'string' || valueType === 'number');
579579
}
580580

581581

src/ng/parse.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ Parser.prototype = {
561561
var token = this.expect();
562562
var filterName = token.text;
563563
var expression = this.text;
564-
var filterCacheKeyInput = '$$filterCache_i_' + filterName + '_' + expression;
565-
var filterCacheKeyResult = '$$filterCache_r_' + filterName + '_' + expression;
564+
var filterCacheKeyInput = filterName + '_i_' + expression;
565+
var filterCacheKeyResult = filterName + '_r_' + expression;
566566
var fn = this.$filter(filterName);
567567
var argsFn;
568568
var args;
@@ -577,6 +577,7 @@ Parser.prototype = {
577577

578578
return valueFn(function $parseFilter(self, locals, input) {
579579
var result;
580+
var filterCache = self.$$filterCache;
580581

581582
if (args) {
582583
args[0] = input;
@@ -593,13 +594,13 @@ Parser.prototype = {
593594
}
594595

595596
if (primitiveInputs) {
596-
if (hasOwnProperty.call(self, filterCacheKeyInput) &&
597-
equals(self[filterCacheKeyInput], args)) {
598-
result = self[filterCacheKeyResult];
597+
if (filterCacheKeyInput in filterCache &&
598+
equals(filterCache[filterCacheKeyInput], args)) {
599+
result = filterCache[filterCacheKeyResult];
599600
} else {
600601
result = fn.apply(undefined, args);
601-
self[filterCacheKeyInput] = shallowCopy(args, []);
602-
self[filterCacheKeyResult] = result;
602+
filterCache[filterCacheKeyInput] = shallowCopy(args, []);
603+
filterCache[filterCacheKeyResult] = result;
603604
}
604605
} else {
605606
result = fn.apply(undefined, args);
@@ -609,13 +610,12 @@ Parser.prototype = {
609610
}
610611

611612
if (isPrimitive(input)) {
612-
if (hasOwnProperty.call(self, filterCacheKeyInput) &&
613-
self[filterCacheKeyInput] === input) {
614-
result = self[filterCacheKeyResult];
613+
if (filterCache[filterCacheKeyInput] === input && (input === undefined || filterCacheKeyInput in filterCache)) {
614+
result = filterCache[filterCacheKeyResult];
615615
} else {
616616
result = fn(input);
617-
self[filterCacheKeyInput] = input;
618-
self[filterCacheKeyResult] = result;
617+
filterCache[filterCacheKeyInput] = input;
618+
filterCache[filterCacheKeyResult] = result;
619619
}
620620
} else {
621621
result = fn(input);

src/ng/rootScope.js

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function $RootScopeProvider(){
136136
this.$$listenerCount = {};
137137
this.$$isolateBindings = {};
138138
this.$$applyAsyncQueue = [];
139+
this.$$filterCache = createMap();
139140
}
140141

141142
/**
@@ -207,6 +208,7 @@ function $RootScopeProvider(){
207208
this.$$listenerCount = {};
208209
this.$id = nextUid();
209210
this.$$ChildScope = null;
211+
this.$$filterCache = createMap();
210212
};
211213
this.$$ChildScope.prototype = this;
212214
}

0 commit comments

Comments
 (0)