[Python-Dev] Issue 19332: Guard against changing dict during iteration
Serhiy Storchaka
storchaka at gmail.com
Wed Nov 6 19:02:26 CET 2013
06.11.13 07:41, Nick Coghlan написав(ла):
> If the benchmark suite indicates there's no measurable speed penalty
> then such a patch may be worth reconsidering.
I don't see any significant speed difference even in artificial
presumably worst case (a lot of items assignment in tight loop).
If you have tests which demonstrate a difference, please show them.
> I'd be astonished if that
> was actually the case, though - the lowest impact approach I can think
> of is to check for live iterators when setting a dict entry, and that
> still has non-trivial size and speed implications.
Actually we should guard not against changing dict during iteration, but
against iterating modifying dict (and only such modifications which
change dict's keys). For this we need only keys modification counter in
a dict and it's copy in an iterator (this doesn't increase memory
requirements however). I suppose Java use same technique in HashMap.
More information about the Python-Dev
mailing list