A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-November/130048.html below:

Guard against changing dict during iteration

[Python-Dev] Issue 19332: Guard against changing dict during iteration [Python-Dev] Issue 19332: Guard against changing dict during iterationSerhiy 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4