mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Check if a thread's target is null in sequencer
Before calling execute, if a thread's target is null, retire that thread. This saves repeatedly checking if the thread's target is null in recursive calls where even if scratch-gui or blocks, or some other related library set the target to null, that will not happen during block execution. It will happen at some time outside of the sequencer letting the sequencer check once instead of execute checking at every recursive level.
This commit is contained in:
parent
4286e3e982
commit
41d6a8f925
2 changed files with 5 additions and 9 deletions
|
@ -113,14 +113,6 @@ const RECURSIVE = true;
|
|||
*/
|
||||
const execute = function (sequencer, thread, recursiveCall) {
|
||||
const runtime = sequencer.runtime;
|
||||
const target = thread.target;
|
||||
|
||||
// Stop if block or target no longer exists.
|
||||
if (target === null) {
|
||||
// No block found: stop the thread; script no longer exists.
|
||||
sequencer.retireThread(thread);
|
||||
return;
|
||||
}
|
||||
|
||||
// Current block to execute is the one on the top of the stack.
|
||||
const currentBlockId = thread.peekStack();
|
||||
|
|
|
@ -197,7 +197,11 @@ class Sequencer {
|
|||
this.runtime.profiler.records.push(
|
||||
this.runtime.profiler.START, executeProfilerId, null, performance.now());
|
||||
}
|
||||
execute(this, thread);
|
||||
if (thread.target === null) {
|
||||
this.retireThread(thread);
|
||||
} else {
|
||||
execute(this, thread);
|
||||
}
|
||||
if (this.runtime.profiler !== null) {
|
||||
// this.runtime.profiler.stop();
|
||||
this.runtime.profiler.records.push(this.runtime.profiler.STOP, performance.now());
|
||||
|
|
Loading…
Reference in a new issue