Skip to content

Commit 1555aaf

Browse files
committed
skip unnecessary _Py_dict_lookup when split table is full.
1 parent 3d8bb6d commit 1555aaf

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

Objects/dictobject.c

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,28 +1879,26 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
18791879
PyObject *key, Py_hash_t hash, PyObject *value)
18801880
{
18811881
PyObject *old_value;
1882+
Py_ssize_t ix;
18821883

18831884
ASSERT_DICT_LOCKED(mp);
18841885

18851886
if (_PyDict_HasSplitTable(mp) && PyUnicode_CheckExact(key)) {
1886-
Py_ssize_t ix = insert_split_key(mp->ma_keys, key, hash);
1887+
ix = insert_split_key(mp->ma_keys, key, hash);
18871888
if (ix != DKIX_EMPTY) {
18881889
insert_split_value(interp, mp, key, value, ix);
18891890
Py_DECREF(key);
18901891
Py_DECREF(value);
18911892
return 0;
18921893
}
1893-
1894-
/* No space in shared keys. Resize and continue below. */
1895-
if (insertion_resize(mp, 1) < 0) {
1894+
// No space in shared keys. Go to insert_combined_dict() below.
1895+
}
1896+
else {
1897+
ix = _Py_dict_lookup(mp, key, hash, &old_value);
1898+
if (ix == DKIX_ERROR)
18961899
goto Fail;
1897-
}
18981900
}
18991901

1900-
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &old_value);
1901-
if (ix == DKIX_ERROR)
1902-
goto Fail;
1903-
19041902
if (ix == DKIX_EMPTY) {
19051903
// insert_combined_dict() will convert from non DICT_KEYS_GENERAL table
19061904
// into DICT_KEYS_GENERAL table if key is not Unicode.
@@ -4377,6 +4375,7 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
43774375
PyDictObject *mp = (PyDictObject *)d;
43784376
PyObject *value;
43794377
Py_hash_t hash;
4378+
Py_ssize_t ix;
43804379
PyInterpreterState *interp = _PyInterpreterState_GET();
43814380

43824381
ASSERT_DICT_LOCKED(d);
@@ -4413,7 +4412,7 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44134412
}
44144413

44154414
if (_PyDict_HasSplitTable(mp) && PyUnicode_CheckExact(key)) {
4416-
Py_ssize_t ix = insert_split_key(mp->ma_keys, key, hash);
4415+
ix = insert_split_key(mp->ma_keys, key, hash);
44174416
if (ix != DKIX_EMPTY) {
44184417
PyObject *value = mp->ma_values->values[ix];
44194418
int already_present = value != NULL;
@@ -4426,19 +4425,16 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44264425
}
44274426
return already_present;
44284427
}
4429-
4430-
/* No space in shared keys. Resize and continue below. */
4431-
if (insertion_resize(mp, 1) < 0) {
4432-
goto error;
4433-
}
4428+
// No space in shared keys. Go to insert_combined_dict() below.
44344429
}
4435-
4436-
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &value);
4437-
if (ix == DKIX_ERROR) {
4438-
if (result) {
4439-
*result = NULL;
4430+
else {
4431+
ix = _Py_dict_lookup(mp, key, hash, &value);
4432+
if (ix == DKIX_ERROR) {
4433+
if (result) {
4434+
*result = NULL;
4435+
}
4436+
return -1;
44404437
}
4441-
return -1;
44424438
}
44434439

44444440
if (ix == DKIX_EMPTY) {
@@ -4468,12 +4464,6 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44684464
*result = incref_result ? Py_NewRef(value) : value;
44694465
}
44704466
return 1;
4471-
4472-
error:
4473-
if (result) {
4474-
*result = NULL;
4475-
}
4476-
return -1;
44774467
}
44784468

44794469
int

0 commit comments

Comments
 (0)