Skip to content

Commit

Permalink
perf: hash the signature to optimize memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Feb 28, 2015
1 parent 35f7eb5 commit 1cd9676
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,15 +856,15 @@
regInvokes[moduleName][type][invokeName].push(signature);
broadcast('ocLazyLoad.componentLoaded', [moduleName, type, invokeName]);
};
var signature = function(data) {
var signature = function signature(data) {
if(angular.isArray(data)) { // arrays are objects, we need to test for it first
return data.toString();
return hashCode(data.toString());
} else if(angular.isObject(data)) { // constants & values for example
return JSON.stringify(data);
return hashCode(JSON.stringify(data));
} else {
if(angular.isDefined(data) && data !== null) {
return data.toString();
} else {
return hashCode(data.toString());
} else { // null & undefined constants
return data;
}
}
Expand Down Expand Up @@ -1005,6 +1005,17 @@
}
}

var hashCode = function hashCode(str) {
var hash = 0, i, chr, len;
if (str.length == 0) return hash;
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};

// Array.indexOf polyfill for IE8
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement, fromIndex) {
Expand Down

0 comments on commit 1cd9676

Please sign in to comment.