Skip to content

Commit d25015b

Browse files
committed
perf: optimize set lookups by inlining set_do_lookup and adding a fast-path for identical Unicode keys
1 parent 564c58c commit d25015b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Objects/setobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ set_compare_frozenset(PySetObject *so, setentry *table, setentry *ep,
182182
}
183183
Py_ssize_t ep_hash = ep->hash;
184184
if (ep_hash == hash) {
185+
if (PyUnicode_CheckExact(startkey)
186+
&& PyUnicode_CheckExact(key)
187+
&& unicode_eq(startkey, key)) {
188+
return SET_LOOKKEY_FOUND;
189+
}
185190
int cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
186191
if (cmp < 0) {
187192
return SET_LOOKKEY_ERROR;
@@ -217,7 +222,7 @@ set_zero_table(setentry *table, size_t size)
217222
/* This must be >= 1 */
218223
#define PERTURB_SHIFT 5
219224

220-
static int
225+
static inline Py_ALWAYS_INLINE int
221226
set_do_lookup(PySetObject *so, setentry *table, size_t mask, PyObject *key,
222227
Py_hash_t hash, setentry **epp, compare_func compare_entry)
223228
{

0 commit comments

Comments
 (0)