mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-134891: Add PyUnstable_Unicode_GET_CACHED_HASH (GH-134892)
This commit is contained in:
parent
343182853f
commit
e413e26719
7 changed files with 55 additions and 5 deletions
|
|
@ -300,6 +300,17 @@ static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
|
|||
}
|
||||
#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
|
||||
|
||||
/* Returns the cached hash, or -1 if not cached yet. */
|
||||
static inline Py_hash_t
|
||||
PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) {
|
||||
assert(PyUnicode_Check(op));
|
||||
#ifdef Py_GIL_DISABLED
|
||||
return _Py_atomic_load_ssize_relaxed(&_PyASCIIObject_CAST(op)->hash);
|
||||
#else
|
||||
return _PyASCIIObject_CAST(op)->hash;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Write into the canonical representation, this function does not do any sanity
|
||||
checks and is intended for usage in loops. The caller should cache the
|
||||
kind and data pointers obtained from other function calls.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue