Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize set and frozenset membership lookup by inlining ``set_do_lookup`` and adding a ``PyUnicode_CheckExact`` fast path to ``set_compare_frozenset``.
7 changes: 6 additions & 1 deletion Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ set_compare_frozenset(PySetObject *so, setentry *table, setentry *ep,
}
Py_ssize_t ep_hash = ep->hash;
if (ep_hash == hash) {
if (PyUnicode_CheckExact(startkey)
&& PyUnicode_CheckExact(key)
&& unicode_eq(startkey, key)) {
return SET_LOOKKEY_FOUND;
}
int cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
if (cmp < 0) {
return SET_LOOKKEY_ERROR;
Expand Down Expand Up @@ -217,7 +222,7 @@ set_zero_table(setentry *table, size_t size)
/* This must be >= 1 */
#define PERTURB_SHIFT 5

static int
static inline Py_ALWAYS_INLINE int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the compiler not already specialising this?

set_do_lookup(PySetObject *so, setentry *table, size_t mask, PyObject *key,
Py_hash_t hash, setentry **epp, compare_func compare_entry)
{
Expand Down
Loading