Skip to content

Commit

Permalink
Intern unique key strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Nov 12, 2014
1 parent 5be14dc commit 9ba96fe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion private.js
Expand Up @@ -49,11 +49,17 @@ var uniqueKeys = create(null);
function makeUniqueKey() {
// Collisions are highly unlikely, but this module is in the business of
// making guarantees rather than safe bets.
do var uniqueKey = strSlice.call(numToStr.call(rand(), 36), 2);
do var uniqueKey = internString(strSlice.call(numToStr.call(rand(), 36), 2));
while (hasOwn.call(uniqueKeys, uniqueKey));
return uniqueKeys[uniqueKey] = uniqueKey;
}

function internString(str) {
var obj = {};
obj[str] = true;
return Object.keys(obj)[0];
}

// External users might find this function useful, but it is not necessary
// for the typical use of this module.
defProp(exports, "makeUniqueKey", makeUniqueKey);
Expand Down

0 comments on commit 9ba96fe

Please sign in to comment.