unicode_get_hash(PyObject *o)
{
assert(PyUnicode_CheckExact(o));
- return _PyASCIIObject_CAST(o)->hash;
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyASCIIObject_CAST(o)->hash);
}
/* Print summary info about the state of the optimized allocator */
}
PyDictObject *mp = (PyDictObject *)op;
- Py_hash_t hash;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- PyErr_FormatUnraisable(warnmsg);
- return NULL;
- }
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ PyErr_FormatUnraisable(warnmsg);
+ return NULL;
}
PyThreadState *tstate = _PyThreadState_GET();
assert(PyDict_CheckExact((PyObject*)mp));
assert(PyUnicode_CheckExact(key));
- Py_hash_t hash = unicode_get_hash(key);
+ Py_hash_t hash = _PyObject_HashFast(key);
if (hash == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- return -1;
- }
+ return -1;
}
return _Py_dict_lookup(mp, key, hash, &value);
return -1;
}
- Py_hash_t hash;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1)
- {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- *result = NULL;
- return -1;
- }
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ *result = NULL;
+ return -1;
}
return _PyDict_GetItemRef_KnownHash((PyDictObject *)op, key, hash, result);
ASSERT_DICT_LOCKED(op);
assert(PyUnicode_CheckExact(key));
- Py_hash_t hash;
- if ((hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- *result = NULL;
- return -1;
- }
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ *result = NULL;
+ return -1;
}
PyObject *value;
PyErr_BadInternalCall();
return NULL;
}
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1)
- {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- return NULL;
- }
+ hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return NULL;
}
#ifdef Py_GIL_DISABLED
Py_hash_t hash;
PyObject *value;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return NULL;
+ hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return NULL;
}
/* namespace 1: globals */
assert(key);
assert(value);
assert(PyDict_Check(mp));
- Py_hash_t hash;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- Py_DECREF(key);
- Py_DECREF(value);
- return -1;
- }
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ Py_DECREF(key);
+ Py_DECREF(value);
+ return -1;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
int
PyDict_DelItem(PyObject *op, PyObject *key)
{
- Py_hash_t hash;
assert(key);
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return -1;
}
return _PyDict_DelItem_KnownHash(op, key, hash);
return 0;
}
- Py_hash_t hash;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- if (result) {
- *result = NULL;
- }
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ if (result) {
+ *result = NULL;
}
+ return -1;
}
return _PyDict_Pop_KnownHash(dict, key, hash, result);
}
Py_hash_t hash;
PyObject *value;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return NULL;
+ hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return NULL;
}
ix = _Py_dict_lookup_threadsafe(mp, key, hash, &value);
if (ix == DKIX_ERROR)
Py_hash_t hash;
Py_ssize_t ix;
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return NULL;
+ hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return NULL;
}
ix = _Py_dict_lookup_threadsafe(self, key, hash, &val);
if (ix == DKIX_ERROR)
return -1;
}
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1) {
- if (result) {
- *result = NULL;
- }
- return -1;
+ hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ if (result) {
+ *result = NULL;
}
+ return -1;
}
if (mp->ma_keys == Py_EMPTY_KEYS) {
int
PyDict_Contains(PyObject *op, PyObject *key)
{
- Py_hash_t hash;
+ Py_hash_t hash = _PyObject_HashFast(key);
- if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
+ if (hash == -1) {
+ return -1;
}
return _PyDict_Contains_KnownHash(op, key, hash);
_PyDict_SetItem_LockHeld(PyDictObject *dict, PyObject *name, PyObject *value)
{
if (value == NULL) {
- Py_hash_t hash;
- if (!PyUnicode_CheckExact(name) || (hash = unicode_get_hash(name)) == -1) {
- hash = PyObject_Hash(name);
- if (hash == -1)
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(name);
+ if (hash == -1) {
+ return -1;
}
return delitem_knownhash_lock_held((PyObject *)dict, name, hash);
} else {
static int
set_add_key(PySetObject *so, PyObject *key)
{
- Py_hash_t hash;
-
- if (!PyUnicode_CheckExact(key) ||
- (hash = _PyASCIIObject_CAST(key)->hash) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return -1;
}
return set_add_entry(so, key, hash);
}
static int
set_contains_key(PySetObject *so, PyObject *key)
{
- Py_hash_t hash;
-
- if (!PyUnicode_CheckExact(key) ||
- (hash = _PyASCIIObject_CAST(key)->hash) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return -1;
}
return set_contains_entry(so, key, hash);
}
static int
set_discard_key(PySetObject *so, PyObject *key)
{
- Py_hash_t hash;
-
- if (!PyUnicode_CheckExact(key) ||
- (hash = _PyASCIIObject_CAST(key)->hash) == -1) {
- hash = PyObject_Hash(key);
- if (hash == -1)
- return -1;
+ Py_hash_t hash = _PyObject_HashFast(key);
+ if (hash == -1) {
+ return -1;
}
return set_discard_entry(so, key, hash);
}