Skip to content

Commit b4b9e33

Browse files
committed
Use _PyDict_Next()
1 parent a55a54e commit b4b9e33

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Objects/dictobject.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8231,15 +8231,14 @@ _shuffle_bits(Py_uhash_t h)
82318231
// Compute hash((key, value)).
82328232
// Code copied from tuple_hash().
82338233
static Py_hash_t
8234-
frozendict_pair_hash(PyObject *key, PyObject *value)
8234+
frozendict_pair_hash(Py_hash_t key_hash, PyObject *value)
82358235
{
8236+
assert(key_hash != (Py_uhash_t)-1);
8237+
82368238
const Py_ssize_t len = 2;
82378239
Py_uhash_t acc = _PyTuple_HASH_XXPRIME_5;
82388240

8239-
Py_uhash_t lane = PyObject_Hash(key);
8240-
if (lane == (Py_uhash_t)-1) {
8241-
return -1;
8242-
}
8241+
Py_uhash_t lane = key_hash;
82438242
acc += lane * _PyTuple_HASH_XXPRIME_2;
82448243
acc = _PyTuple_HASH_XXROTATE(acc);
82458244
acc *= _PyTuple_HASH_XXPRIME_1;
@@ -8275,10 +8274,11 @@ frozendict_hash(PyObject *op)
82758274
PyDictObject *mp = _PyAnyDict_CAST(op);
82768275
Py_uhash_t hash = 0;
82778276

8278-
PyObject *key, *value; // borrowed refs
8277+
PyObject *value; // borrowed ref
82798278
Py_ssize_t pos = 0;
8280-
while (PyDict_Next(op, &pos, &key, &value)) {
8281-
Py_hash_t pair_hash = frozendict_pair_hash(key, value);
8279+
Py_hash_t key_hash;
8280+
while (_PyDict_Next(op, &pos, NULL, &value, &key_hash)) {
8281+
Py_hash_t pair_hash = frozendict_pair_hash(key_hash, value);
82828282
if (pair_hash == -1) {
82838283
return -1;
82848284
}

0 commit comments

Comments
 (0)