From 73f62ef36c4d09052a1fc1cf6d68ef1d9c0a840f Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 27 Feb 2012 14:45:01 -0500 Subject: [PATCH] trying to reduce cost of namespace.get --- js-assembler/runtime-src/baselib-modules.js | 26 ++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/js-assembler/runtime-src/baselib-modules.js b/js-assembler/runtime-src/baselib-modules.js index a6d336a..5a4f258 100644 --- a/js-assembler/runtime-src/baselib-modules.js +++ b/js-assembler/runtime-src/baselib-modules.js @@ -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; };