Optimize replaceStack for inline methods
Only use case was with inline input so most of this code was unnecessary.
This commit is contained in:
@@ -731,9 +731,7 @@ JavaScriptCompiler.prototype = {
|
||||
this.flushInline();
|
||||
|
||||
var stack = this.incrStack();
|
||||
if (item) {
|
||||
this.pushSource(stack + " = " + item + ";");
|
||||
}
|
||||
this.pushSource(stack + " = " + item + ";");
|
||||
this.compileStack.push(stack);
|
||||
return stack;
|
||||
},
|
||||
@@ -745,54 +743,40 @@ JavaScriptCompiler.prototype = {
|
||||
createdStack,
|
||||
usedLiteral;
|
||||
|
||||
// If we are currently inline then we want to merge the inline statement into the
|
||||
// replacement statement via ','
|
||||
if (inline) {
|
||||
var top = this.popStack(true);
|
||||
/* istanbul ignore next */
|
||||
if (!this.isInline()) {
|
||||
throw new Exception('replaceStack on non-inline');
|
||||
}
|
||||
|
||||
if (top instanceof Literal) {
|
||||
// Literals do not need to be inlined
|
||||
stack = top.value;
|
||||
usedLiteral = true;
|
||||
// We want to merge the inline statement into the replacement statement via ','
|
||||
var top = this.popStack(true);
|
||||
|
||||
if (chain) {
|
||||
prefix = stack;
|
||||
}
|
||||
} else {
|
||||
// Get or create the current stack name for use by the inline
|
||||
createdStack = !this.stackSlot;
|
||||
var name = !createdStack ? this.topStackName() : this.incrStack();
|
||||
if (top instanceof Literal) {
|
||||
// Literals do not need to be inlined
|
||||
stack = top.value;
|
||||
usedLiteral = true;
|
||||
|
||||
prefix = '(' + this.push(name) + ' = ' + top + (chain ? ')' : '),');
|
||||
stack = this.topStack();
|
||||
if (chain) {
|
||||
prefix = stack;
|
||||
}
|
||||
} else {
|
||||
// Get or create the current stack name for use by the inline
|
||||
createdStack = !this.stackSlot;
|
||||
var name = !createdStack ? this.topStackName() : this.incrStack();
|
||||
|
||||
prefix = '(' + this.push(name) + ' = ' + top + (chain ? ')' : '),');
|
||||
stack = this.topStack();
|
||||
}
|
||||
|
||||
var item = callback.call(this, stack);
|
||||
|
||||
if (inline) {
|
||||
if (!usedLiteral) {
|
||||
this.popStack();
|
||||
}
|
||||
if (createdStack) {
|
||||
this.stackSlot--;
|
||||
}
|
||||
this.push('(' + prefix + item + ')');
|
||||
} else {
|
||||
// Prevent modification of the context depth variable. Through replaceStack
|
||||
if (!/^stack/.test(stack)) {
|
||||
stack = this.nextStack();
|
||||
}
|
||||
|
||||
this.pushSource(stack + " = (" + prefix + item + ");");
|
||||
if (!usedLiteral) {
|
||||
this.popStack();
|
||||
}
|
||||
return stack;
|
||||
},
|
||||
|
||||
nextStack: function() {
|
||||
return this.pushStack();
|
||||
if (createdStack) {
|
||||
this.stackSlot--;
|
||||
}
|
||||
this.push('(' + prefix + item + ')');
|
||||
},
|
||||
|
||||
incrStack: function() {
|
||||
|
||||
Reference in New Issue
Block a user