2016-04-15 11:01 GMT+02:00 Antoine Pitrou <antoine@python.org>:
Victor Stinner <victor.stinner <at> gmail.com> writes:
You're right that incrementing the global version is useless for these specific cases, and using the version 0 should work. It only matters that the version (version? version tag?) is different.
Why do this? It's a nice property that two dicts always have different version tags, and now you're killing this property for... no obvious reason?
I guess that the reason is to reduce *a little bit* the risk of integer overflow (especially the bug when a guard doesn't see a change between new_version = old_version % 2**64).
Do you really think dict.clear() is in need of micro-optimizing a couple CPU cycles away?
The advantage of having a different version for empty dict is to be able to use the version to check that they are different. Using the dictionary pointer is not enough, since it's common that a new dictionary gets the address of a previously destroyed dictionary. This case can be avoided if you keep dictionaries alive by keeping a strong reference, but there are good reasons to not keep a strong reference. Victor