On Tue, 15 Sep 2020 at 09:22, Inada Naoki <songofaca...@gmail.com> wrote:
>
> On Tue, Sep 15, 2020 at 5:08 AM Marco Sulla
> <marco.sulla.pyt...@gmail.com> wrote:
> >
> > 1. How can we check the size of an object only if it's an iterable
> > using the Python C API?
>
> There is no good way. Additionally, we need to know distinct count if
> we want to preallocate hash table.
> For example, `len(dict(["foo"]*1000))` is 1, not 1000.
> [...]
> We have "one big resize" logic in dict_merge already.
> And I use dummy empty dictkeys for new empty dict.
> So we don't allocate any temporary, intermediate dictkey object.

Well, yes, but only for the first positional argument and if it's a map.
I would be able to resize to the maximum possible size, that is
len(arg) + len(kwarg). Of course the size can be overestimated, but I
suppose the overlaps are very rare and small.

The problem is that if I do this resize in dict_new, when the compilation does

python -E -S -m sysconfig --generate-posix-vars

a segfault happens. If I reintroduce the temporary dummy keys, it works.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/AK35PRDPACXMHQ443CPB7GTYZXHTUQYV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to