gh-131510: Use PyUnstable_Unicode_GET_CACHED_HASH() (GH-141520)

Replace code that directly accesses PyASCIIObject.hash with
PyUnstable_Unicode_GET_CACHED_HASH().

Remove redundant "assert(PyUnicode_Check(op))" from
PyUnstable_Unicode_GET_CACHED_HASH(), _PyASCIIObject_CAST() already
implements the check.
This commit is contained in:
Victor Stinner 2025-11-14 11:13:24 +01:00 committed by GitHub
parent 181a2f4f2e
commit 3bacae5598
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 3 additions and 6 deletions

View file

@ -6036,7 +6036,7 @@ static PyObject *
update_cache(struct type_cache_entry *entry, PyObject *name, unsigned int version_tag, PyObject *value)
{
_Py_atomic_store_ptr_relaxed(&entry->value, value); /* borrowed */
assert(_PyASCIIObject_CAST(name)->hash != -1);
assert(PyUnstable_Unicode_GET_CACHED_HASH(name) != -1);
OBJECT_STAT_INC_COND(type_cache_collisions, entry->name != Py_None && entry->name != name);
// We're releasing this under the lock for simplicity sake because it's always a
// exact unicode object or Py_None so it's safe to do so.