From 0e44ac2de01fc66e970133d98962b62ef8be6fbd Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 26 Aug 2014 13:40:44 -0700 Subject: [PATCH] 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 --- src/apis.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/apis.js b/src/apis.js index 3b0a22ab3191..36e0a103ff82 100644 --- a/src/apis.js +++ b/src/apis.js @@ -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)(); } + return key; + } + + var objType = typeof obj; + if (objType == 'function' || (objType == 'object' && obj !== null)) { + key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)(); } else { - key = obj; + key = objType + ':' + obj; } - return objType + ':' + key; + return key; } /**