Skip to content

Commit

Permalink
[FIX] misc: allow to delete multiple elements from set
Browse files Browse the repository at this point in the history
`JetSet.deleteMany` only deletes the first element found
in the set, instead of deleting all elements.

The reason is `wasDeleted ||= super.delete(element);`.

It's equivalent to `wasDeleted = wasDeleted || super.delete(element);`
and as soon as `wasDeleted` is true (when the first element is deleted)
the right-hand part (`|| super.delete(element)`) is no longer executed.

I simplified the method by removing the return value. It's never used
and this data structure has been removed in future versions anyway.

Note that it didn't cause any actual functional bug; only some useless
computation in some cases.

Task: 4036899
Part-of: #4589
Signed-off-by: Vincent Schippefilt (vsc) <[email protected]>
  • Loading branch information
LucasLefevre committed Jul 5, 2024
1 parent 4d2c4ad commit c98b193
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/helpers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,10 @@ export class JetSet<T> extends Set<T> {
}
return this;
}
deleteMany(iterable: Iterable<T>): boolean {
let wasDeleted = false;
deleteMany(iterable: Iterable<T>) {
for (const element of iterable) {
wasDeleted ||= super.delete(element);
super.delete(element);
}
return wasDeleted;
}
}

Expand Down

0 comments on commit c98b193

Please sign in to comment.