[issue21507] set and frozenset constructor should use operator.length_hint to guess the size of the iterator
STINNER Victor
report at bugs.python.org
Thu May 15 00:18:50 CEST 2014
STINNER Victor added the comment:
frozenset constructor has different implementations depending on the input type: set (or frozenset), dict or iterator. The constructor preallocates the frozenset for set and dict, but not for generic iterator and so the set may have a suboptimal size.
Attached patch set_length_hint.patch optimizes also the 3rd case using operator.length_hint (PyObject_LengthHint in C).
Since it is an optimization, I prefer to only apply it to Python 3.5 to limit the risk of regression.
----------
keywords: +patch
nosy: +haypo
title: memory used by frozenset created from set differs from that of frozenset created from other iterable -> set and frozenset constructor should use operator.length_hint to guess the size of the iterator
versions: +Python 3.5 -Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file35255/set_length_hint.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21507>
_______________________________________
More information about the Python-bugs-list
mailing list