mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-13 00:28:10 +08:00
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:
22
src/apis.js
22
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)();
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user