Skip to content

Commit

Permalink
perf: use faster check for $$ prefix
Browse files Browse the repository at this point in the history
Use two calls to charAt instead of substr to detect a $$prefix in the shallowCopy functions.
This makes shallowCopy 25-50% faster (depending on which browser is used).
http://jsperf.com/angular-shallow-copy

Closes angular#5457
  • Loading branch information
kseamon authored and IgorMinar committed Dec 17, 2013
1 parent 5c97731 commit cb29632
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ function shallowCopy(src, dst) {
for(var key in src) {
// shallowCopy is only ever called by $compile nodeLinkFn, which has control over src
// so we don't need to worry about using our custom hasOwnProperty here
if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') {
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
dst[key] = src[key];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function shallowClearAndCopy(src, dst) {
});

for (var key in src) {
if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') {
if (src.hasOwnProperty(key) && key.charAt(0) !== '$' && key.charAt(1) !== '$') {
dst[key] = src[key];
}
}
Expand Down

0 comments on commit cb29632

Please sign in to comment.