mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 17:09:50 -05:00
In place filter threads at end of stepThreads
Skip a large array allocation by filtering done threads in place with a for loop.
This commit is contained in:
parent
4e24a3f380
commit
6d82c0f115
1 changed files with 20 additions and 5 deletions
|
@ -84,13 +84,28 @@ class Sequencer {
|
||||||
ranFirstTick = true;
|
ranFirstTick = true;
|
||||||
}
|
}
|
||||||
// Filter inactive threads from `this.runtime.threads`.
|
// Filter inactive threads from `this.runtime.threads`.
|
||||||
this.runtime.threads = this.runtime.threads.filter((thread, i) => {
|
numActiveThreads = 0;
|
||||||
|
for (let i = 0; i < this.runtime.threads.length; i++) {
|
||||||
|
const thread = this.runtime.threads[i];
|
||||||
if (doneThreads[i] === null) {
|
if (doneThreads[i] === null) {
|
||||||
return false;
|
this.runtime.threads[numActiveThreads] = thread;
|
||||||
|
numActiveThreads++;
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
});
|
this.runtime.threads.length = numActiveThreads;
|
||||||
return doneThreads.filter(Boolean);
|
|
||||||
|
// Filter undefined and null values from `doneThreads`.
|
||||||
|
let numDoneThreads = 0;
|
||||||
|
for (let i = 0; i < doneThreads.length; i++) {
|
||||||
|
const maybeThread = doneThreads[i];
|
||||||
|
if (maybeThread !== null) {
|
||||||
|
doneThreads[numDoneThreads] = maybeThread;
|
||||||
|
numDoneThreads++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
doneThreads.length = numDoneThreads;
|
||||||
|
|
||||||
|
return doneThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue