removed useless property accesses from for-of

This commit is contained in:
satyr
2010-09-22 12:55:19 +09:00
parent 07d9e9b71e
commit 540783a6dd
2 changed files with 9 additions and 8 deletions

View File

@@ -1648,8 +1648,8 @@
return n instanceof CodeNode; return n instanceof CodeNode;
}); });
scope = o.scope; scope = o.scope;
name = (this.name && this.name.compile(o)) || scope.freeVariable('i'); name = this.name == null ? undefined : this.name.compile(o);
index = this.index && this.index.compile(o); index = this.index == null ? undefined : this.index.compile(o);
if (name && !this.pattern && (range || !codeInBody)) { if (name && !this.pattern && (range || !codeInBody)) {
scope.find(name, { scope.find(name, {
immediate: true immediate: true
@@ -1665,13 +1665,13 @@
} }
ivar = (function() { ivar = (function() {
if (codeInBody) { if (codeInBody) {
return scope.freeVariable('i'); return null;
} else if (range) { } else if (range) {
return name; return name;
} else { } else {
return index || scope.freeVariable('i'); return index;
} }
})(); })() || scope.freeVariable('i');
varPart = ''; varPart = '';
guardPart = ''; guardPart = '';
body = Expressions.wrap([this.body]); body = Expressions.wrap([this.body]);

View File

@@ -1380,12 +1380,13 @@ exports.ForNode = class ForNode extends BaseNode
source = if range then @source.base else @source source = if range then @source.base else @source
codeInBody = @body.contains (n) -> n instanceof CodeNode codeInBody = @body.contains (n) -> n instanceof CodeNode
scope = o.scope scope = o.scope
name = (@name and @name.compile(o)) or scope.freeVariable 'i' name = @name ?.compile o
index = @index and @index.compile o index = @index?.compile o
scope.find(name, immediate: yes) if name and not @pattern and (range or not codeInBody) scope.find(name, immediate: yes) if name and not @pattern and (range or not codeInBody)
scope.find(index, immediate: yes) if index scope.find(index, immediate: yes) if index
rvar = scope.freeVariable 'result' unless topLevel rvar = scope.freeVariable 'result' unless topLevel
ivar = if codeInBody then scope.freeVariable 'i' else if range then name else index or scope.freeVariable 'i' ivar = (if codeInBody then null else if range then name else index) or
scope.freeVariable 'i'
varPart = '' varPart = ''
guardPart = '' guardPart = ''
body = Expressions.wrap([@body]) body = Expressions.wrap([@body])