refactor(hashKey): don't generate memory garbage

we now store both the object type and the id as the hashkey and return it for all objects.

for primitives we still have to do string concatination because we can't use expandos on them to
store the hashkey
This commit is contained in:
Igor Minar
2014-08-26 13:40:44 -07:00
parent 5a1a0c9622
commit 0e44ac2de0

View File

@@ -14,21 +14,23 @@
* The resulting string key is in 'type:hashKey' format.
*/
function hashKey(obj, nextUidFn) {
var objType = typeof obj,
key;
var key = obj && obj.$$hashKey;
if (objType == 'function' || (objType == 'object' && obj !== null)) {
if (typeof (key = obj.$$hashKey) == 'function') {
// must invoke on object to keep the right this
if (key) {
if (typeof key === 'function') {
key = obj.$$hashKey();
} else if (key === undefined) {
key = obj.$$hashKey = (nextUidFn || nextUid)();
}
} else {
key = obj;
return key;
}
return objType + ':' + key;
var objType = typeof obj;
if (objType == 'function' || (objType == 'object' && obj !== null)) {
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
} else {
key = objType + ':' + obj;
}
return key;
}
/**