diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-10-11 11:07:42 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-10-11 11:07:42 +0300 |
commit | 172aa7a93ccd39feceefa058ad008e19eec0a073 (patch) | |
tree | 31ac9281110909698cdaef9d1cc2cb08c3722924 /lib/scope.js | |
parent | 5053a29bc0b723bbf468f50e0434c3eff38600e2 (diff) | |
download | tracifyjs-172aa7a93ccd39feceefa058ad008e19eec0a073.tar.gz tracifyjs-172aa7a93ccd39feceefa058ad008e19eec0a073.zip |
cleanup
- use prototype-less objects where feasible (minor speed improvement)
- get rid of HOP
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/scope.js b/lib/scope.js index 40237b39..acc6fa25 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -75,7 +75,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ // pass 1: setup scope chaining and handle definitions var self = this; var scope = self.parent_scope = null; - var labels = {}; + var labels = Object.create(null); var tw = new TreeWalker(function(node, descend){ if (node instanceof AST_Scope) { node.init_scope_vars(); @@ -157,7 +157,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ // pass 2: find back references and eval var func = null; - var globals = self.globals = {}; + var globals = self.globals = Object.create(null); var tw = new TreeWalker(function(node, descend){ if (node instanceof AST_Lambda) { var prev_func = func; @@ -175,7 +175,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ var sym = node.scope.find_variable(name); if (!sym) { var g; - if (HOP(globals, name)) { + if (globals[name]) { g = globals[name]; } else { g = new SymbolDef(self, node); @@ -202,8 +202,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){ AST_Scope.DEFMETHOD("init_scope_vars", function(){ this.directives = []; // contains the directives defined in this scope, i.e. "use strict" - this.variables = {}; // map name to AST_SymbolVar (variables defined in this scope; includes functions) - this.functions = {}; // map name to AST_SymbolDefun (functions defined in this scope) + this.variables = Object.create(null); // map name to AST_SymbolVar (variables defined in this scope; includes functions) + this.functions = Object.create(null); // map name to AST_SymbolDefun (functions defined in this scope) this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval` this.parent_scope = null; // the parent scope @@ -245,9 +245,8 @@ AST_LabelRef.DEFMETHOD("reference", function(){ AST_Scope.DEFMETHOD("find_variable", function(name){ if (name instanceof AST_Symbol) name = name.name; - return HOP(this.variables, name) - ? this.variables[name] - : (this.parent_scope && this.parent_scope.find_variable(name)); + return this.variables[name] + || (this.parent_scope && this.parent_scope.find_variable(name)); }); AST_Scope.DEFMETHOD("has_directive", function(value){ @@ -261,7 +260,7 @@ AST_Scope.DEFMETHOD("def_function", function(symbol){ AST_Scope.DEFMETHOD("def_variable", function(symbol){ var def; - if (!HOP(this.variables, symbol.name)) { + if (!this.variables[symbol.name]) { def = new SymbolDef(this, symbol); this.variables[symbol.name] = def; def.global = !this.parent_scope; @@ -351,7 +350,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ var p = tw.parent(); var is_setget = p instanceof AST_ObjectSetter || p instanceof AST_ObjectGetter; var a = node.variables; - for (var i in a) if (HOP(a, i)) { + for (var i in a) { var symbol = a[i]; if (!(is_setget && symbol instanceof AST_SymbolLambda)) { if (options.except.indexOf(symbol.name) < 0) { @@ -450,15 +449,14 @@ var base54 = (function() { var string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789"; var chars, frequency; function reset() { - frequency = {}; + frequency = Object.create(null); chars = string.split(""); chars.map(function(ch){ frequency[ch] = 0 }); } base54.consider = function(str){ for (var i = str.length; --i >= 0;) { var ch = str.charAt(i); - if (string.indexOf(ch) >= 0) - ++frequency[ch]; + ++frequency[ch]; } }; base54.sort = function() { |