[issue29312] Use FASTCALL in dict.update()

Inada Naoki report at bugs.python.org
Thu Jul 4 07:55:14 EDT 2019


Inada Naoki <songofacandy at gmail.com> added the comment:

> The unpacking is only a problem if you insist on using PyDict_Merge(). It would be perfectly possible to implement dict merging from a tuple+vector instead of from a dict. In that case, there shouldn't be a performance penalty.

Really?

```
class K:
    def __eq__(self, other):
        return True
    def __hash__(self):
        time.sleep(10)
        return 42

d1 = {"foo": 1, "bar": 2, "baz": 3, K(): 4}
d2 = dict(**d1)
```

I think `dict(**d1)` doesn't call K.__hash__() in this example, because hash value is cached in d1.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue29312>
_______________________________________


More information about the Python-bugs-list mailing list