Let Set.prototype.add() accept multiple args like Array.prototype.push()

Let Set.prototype.add() accept multiple args like Array.prototype.push()

1 Like

If we do this, please let's not reinvent the nasty gotcha with Array.prototype.push() where you get implementation-specific limits on the number of arguments you can push because it transfers everything on the stack.

I think there should be separate pushAll() and addAll() methods that accept an array or iterable, rather than relying on multiple arguments.

1 Like

Personally, I'd rather both to exist. Multi-arg set and push are useful in their own right (though add does (un)helpfully return this - I wish it returned whether the key was already present instead), and can be really fast as they require minimal allocation. Iterable-driven pushAll/addAll have their own uses, too, as they efficiently deal with large collections of values without polluting the stack and can be much more straightforwardly translated to memcpy.

Currently, I exclusively use .push, but I never use .push(...values) unless values is itself a rest parameter or in the fleetingly rare event where it actually provides a noticeable performance boost (which I've encountered maybe once ever).