mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Merge pull request #411 from griffpatch/optimisation/reuseStackForNextBlock
Optimisation - Recycle Stack Frame for cosecutive block execution
This commit is contained in:
commit
bb7c411edb
1 changed files with 17 additions and 9 deletions
|
@ -115,6 +115,22 @@ Thread.prototype.pushStack = function (blockId) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the stack frame for use by the next block.
|
||||||
|
* (avoids popping and re-pushing a new stack frame - keeps the warpmode the same
|
||||||
|
* @param {string} blockId Block ID to push to stack.
|
||||||
|
*/
|
||||||
|
Thread.prototype.reuseStackForNextBlock = function (blockId) {
|
||||||
|
this.stack[this.stack.length - 1] = blockId;
|
||||||
|
var frame = this.stackFrames[this.stackFrames.length - 1];
|
||||||
|
frame.isLoop = false;
|
||||||
|
// frame.warpMode = warpMode; // warp mode stays the same when reusing the stack frame.
|
||||||
|
frame.reported = {};
|
||||||
|
frame.waitingReporter = null;
|
||||||
|
frame.params = {};
|
||||||
|
frame.executionContext = {};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pop last block on the stack and its stack frame.
|
* Pop last block on the stack and its stack frame.
|
||||||
* @return {string} Block ID popped from the stack.
|
* @return {string} Block ID popped from the stack.
|
||||||
|
@ -203,15 +219,7 @@ Thread.prototype.atStackTop = function () {
|
||||||
*/
|
*/
|
||||||
Thread.prototype.goToNextBlock = function () {
|
Thread.prototype.goToNextBlock = function () {
|
||||||
var nextBlockId = this.target.blocks.getNextBlock(this.peekStack());
|
var nextBlockId = this.target.blocks.getNextBlock(this.peekStack());
|
||||||
// Copy warp mode to next block.
|
this.reuseStackForNextBlock(nextBlockId);
|
||||||
var warpMode = this.peekStackFrame().warpMode;
|
|
||||||
// The current block is on the stack - pop it and push the next.
|
|
||||||
// Note that this could push `null` - that is handled by the sequencer.
|
|
||||||
this.popStack();
|
|
||||||
this.pushStack(nextBlockId);
|
|
||||||
if (this.peekStackFrame()) {
|
|
||||||
this.peekStackFrame().warpMode = warpMode;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue