Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Pre-compute empty tuple singleton
  • Loading branch information
mdboom committed Mar 21, 2025
commit 40ad9fca75c0a17df4fbe88f1ba5811d14692723
3 changes: 3 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ extern PyTypeObject _PyExc_MemoryError;
}, \
.tuple_empty = { \
.ob_base = _PyVarObject_HEAD_INIT(&PyTuple_Type, 0), \
/* Using the hash constants in tupleobject.c
_PyHASH_XXPRIME_5 + (_PyHASH_XXPRIME_5 ^ 3527539UL) */ \
.ob_hash = 5740354900026072187, \
}, \
.hamt_bitmap_node_empty = { \
.ob_base = _PyVarObject_HEAD_INIT(&_PyHamt_BitmapNode_Type, 0), \
Expand Down
5 changes: 0 additions & 5 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,6 @@ tuple_hash(PyObject *op)
{
PyTupleObject *v = _PyTuple_CAST(op);

// For the empty singleton, we don't need to dereference the pointer
if (op == (PyObject *)&_Py_SINGLETON(tuple_empty)) {
return _PyHASH_XXPRIME_5 + (_PyHASH_XXPRIME_5 ^ 3527539UL);
}

if (v->ob_hash != (Py_uhash_t)-1) {
return v->ob_hash;
}
Expand Down