trying to reduce cost of namespace.get

This commit is contained in:
Danny Yoo 2012-02-27 14:45:01 -05:00
parent 40b616e9ea
commit 73f62ef36c

View File

@ -9,28 +9,21 @@
var Namespace = function(modrec) {
this.modrec = modrec;
// string -> integer
// Returns the position within the prefix that we should be looking.
this.mapping = {};
this.prefix = void(0);
this.extra = {};
};
Namespace.prototype.get = function(name) {
var i;
if (this.mapping.hasOwnProperty(name)) {
return this.modrec.prefix[this.mapping[name]];
return this.prefix[this.mapping[name]];
}
if (this.extra.hasOwnProperty(name)) {
return this.extra[name];
}
if (this.modrec.prefix) {
for (i = 0; i < len; i++) {
if (this.modrec.prefix.names[i] === name) {
this.mapping[name] = i;
return this.modrec.prefix[this.mapping[name]];
}
}
}
return void(0);
};
@ -46,6 +39,7 @@
delete this.extra[name];
}
}
this.prefix = prefix;
};
Namespace.prototype.hasKey = function(name) {
@ -53,24 +47,14 @@
};
Namespace.prototype.set = function(name, value) {
var i;
if (this.mapping.hasOwnProperty(name)) {
this.modrec.prefix[this.mapping[name]] = value;
this.prefix[this.mapping[name]] = value;
return;
};
if (this.extra.hasOwnProperty(name)) {
this.extra[name] = value;
return;
}
if (this.modrec.prefix) {
for (i = 0; i < len; i++) {
if (this.modrec.prefix.names[i] === name) {
this.mapping[name] = i;
this.modrec.prefix[this.mapping[name]] = value;
return;
}
}
}
this.extra[name] = value;
return;
};