tc39 / proposal-set-methods

Proposal for new Set methods in JS
https://tc39.github.io/proposal-set-methods/
Other
655 stars 15 forks source link

Normative: guard against re-visits in intersection iteration #87

Closed bakkot closed 1 year ago

bakkot commented 1 year ago

Fixes https://github.com/tc39/proposal-set-methods/issues/83.

There's actually two places the guard could go: before or after the call to _otherRec_.[[Has]] for this element. I initially put it before, which theoretically minimizes work (don't do the call if you don't need to), but have switched it to after on the assumption that actual engines won't need to do this as a separate step - they can just perform the "add to set" operation and it will not add a duplicate element.

zloirock commented 1 year ago

I don't think that after #86 this is required. Removed elements replaced via empty, added again elements will not be visited since they are out of iteration range since the initial number of elements is cached.

bakkot commented 1 year ago

The initial number of elements is not cached; it is updated each time through the loop (just like in Set.prototype.forEach).

zloirock commented 1 year ago

Ah, yes, I missed additional 1. Set _thisSize_ to the number of elements of _O_.[[SetData]]. step.