Directly call Set.prototype.delete in the ChunkedStreamManager code

There's no point in first checking if a value exists in a Set before deleting it, and this is just a left-over from before the code used Maps and Sets.

Also, remove a couple of unnecessary comments describing how `Set.prototype.add` works (when those where added there wasn't much Set usage in the code-base).
This commit is contained in:
Jonas Jenwald
2026-10-03 18:38:26 +02:00
parent d0991a0d53
commit 1316be0dca
+1 -7
View File
@@ -82,8 +82,6 @@ class ChunkedStream extends Stream {
const endChunk = Math.floor((end - 1) / chunkSize) + 1;
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
// Since a value can only occur *once* in a `Set`, there's no need to
// manually check `Set.prototype.has()` before adding the value here.
this._loadedChunks.add(curChunk);
}
}
@@ -107,8 +105,6 @@ class ChunkedStream extends Stream {
: Math.floor(position / this.chunkSize);
for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
// Since a value can only occur *once* in a `Set`, there's no need to
// manually check `Set.prototype.has()` before adding the value here.
this._loadedChunks.add(curChunk);
}
}
@@ -469,9 +465,7 @@ class ChunkedStreamManager {
for (const requestId of requestIds) {
const chunksNeeded = this.#chunksNeededByRequest.get(requestId);
if (chunksNeeded.has(curChunk)) {
chunksNeeded.delete(curChunk);
}
chunksNeeded.delete(curChunk);
if (chunksNeeded.size > 0) {
continue;