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:
Michael "Z" Goddard 2018-01-24 15:03:57 -05:00
parent 4286e3e982
commit 41d6a8f925
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
2 changed files with 5 additions and 9 deletions

View file

@ -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();

View file

@ -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());