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:
@@ -301,7 +301,6 @@ static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
|
|||||||
/* Returns the cached hash, or -1 if not cached yet. */
|
/* Returns the cached hash, or -1 if not cached yet. */
|
||||||
static inline Py_hash_t
|
static inline Py_hash_t
|
||||||
PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) {
|
PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) {
|
||||||
assert(PyUnicode_Check(op));
|
|
||||||
#ifdef Py_GIL_DISABLED
|
#ifdef Py_GIL_DISABLED
|
||||||
return _Py_atomic_load_ssize_relaxed(&_PyASCIIObject_CAST(op)->hash);
|
return _Py_atomic_load_ssize_relaxed(&_PyASCIIObject_CAST(op)->hash);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -863,8 +863,7 @@ static inline Py_hash_t
|
|||||||
_PyObject_HashFast(PyObject *op)
|
_PyObject_HashFast(PyObject *op)
|
||||||
{
|
{
|
||||||
if (PyUnicode_CheckExact(op)) {
|
if (PyUnicode_CheckExact(op)) {
|
||||||
Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(
|
Py_hash_t hash = PyUnstable_Unicode_GET_CACHED_HASH(op);
|
||||||
_PyASCIIObject_CAST(op)->hash);
|
|
||||||
if (hash != -1) {
|
if (hash != -1) {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -400,8 +400,7 @@ static int _PyObject_InlineValuesConsistencyCheck(PyObject *obj);
|
|||||||
static inline Py_hash_t
|
static inline Py_hash_t
|
||||||
unicode_get_hash(PyObject *o)
|
unicode_get_hash(PyObject *o)
|
||||||
{
|
{
|
||||||
assert(PyUnicode_CheckExact(o));
|
return PyUnstable_Unicode_GET_CACHED_HASH(o);
|
||||||
return FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyASCIIObject_CAST(o)->hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print summary info about the state of the optimized allocator */
|
/* Print summary info about the state of the optimized allocator */
|
||||||
|
|||||||
@@ -6036,7 +6036,7 @@ static PyObject *
|
|||||||
update_cache(struct type_cache_entry *entry, PyObject *name, unsigned int version_tag, PyObject *value)
|
update_cache(struct type_cache_entry *entry, PyObject *name, unsigned int version_tag, PyObject *value)
|
||||||
{
|
{
|
||||||
_Py_atomic_store_ptr_relaxed(&entry->value, value); /* borrowed */
|
_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);
|
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
|
// 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.
|
// exact unicode object or Py_None so it's safe to do so.
|
||||||
|
|||||||
Reference in New Issue
Block a user