Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Faster SideTable
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Aug 26, 2013
1 parent b11b32e commit 473916e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/sidetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ if (typeof WeakMap !== 'undefined' && navigator.userAgent.indexOf('Firefox/') <
} else {
(function() {
var defineProperty = Object.defineProperty;
var hasOwnProperty = Object.hasOwnProperty;
var counter = new Date().getTime() % 1e9;
var counter = Date.now() % 1e9;

SideTable = function() {
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
};

SideTable.prototype = {
set: function(key, value) {
defineProperty(key, this.name, {value: value, writable: true});
var entry = key[this.name];
if (entry && entry[0] === key)
entry[1] = value;
else
defineProperty(key, this.name, {value: [key, value], writable: true});
},
get: function(key) {
return hasOwnProperty.call(key, this.name) ? key[this.name] : undefined;
var entry;
return (entry = key[this.name]) && entry[0] === key ?
entry[1] : undefined;
},
delete: function(key) {
this.set(key, undefined);
Expand Down

0 comments on commit 473916e

Please sign in to comment.