diff options
| author | Karl Seamon | 2013-12-17 14:22:04 -0500 | 
|---|---|---|
| committer | Igor Minar | 2013-12-17 11:43:57 -0800 | 
| commit | cb29632a5802e930262919b3db64ca4806c5cfc7 (patch) | |
| tree | aada5b0eade603bd113b3c333192c64e3f829fe1 | |
| parent | 5c97731a22ed87d64712e673efea0e8a05eae65f (diff) | |
| download | angular.js-cb29632a5802e930262919b3db64ca4806c5cfc7.tar.bz2 | |
perf: use faster check for $$ prefix
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 #5457
| -rw-r--r-- | src/Angular.js | 2 | ||||
| -rw-r--r-- | src/ngResource/resource.js | 2 | 
2 files changed, 2 insertions, 2 deletions
| diff --git a/src/Angular.js b/src/Angular.js index e32c3739..88ea452b 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -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];      }    } diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 281dd4ac..a007c7b1 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -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];      }    } | 
