mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 15:32:40 -05:00
Optimisation - Recycle Stack Frame for cosecutive blocks
This saves popping, destroying, recreating, and pushing the stack frame, and then reassigning the warp mode attribute for every block to block step in the execution.
This commit is contained in:
parent
824628220c
commit
fbf2c0c345
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