@@ -427,7 +427,7 @@ static inline Py_hash_t
427
427
unicode_get_hash (PyObject * o )
428
428
{
429
429
assert (PyUnicode_CheckExact (o ));
430
- return _PyASCIIObject_CAST (o )-> hash ;
430
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyASCIIObject_CAST (o )-> hash ) ;
431
431
}
432
432
433
433
/* Print summary info about the state of the optimized allocator */
@@ -2170,13 +2170,10 @@ dict_getitem(PyObject *op, PyObject *key, const char *warnmsg)
2170
2170
}
2171
2171
PyDictObject * mp = (PyDictObject * )op ;
2172
2172
2173
- Py_hash_t hash ;
2174
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2175
- hash = PyObject_Hash (key );
2176
- if (hash == -1 ) {
2177
- PyErr_FormatUnraisable (warnmsg );
2178
- return NULL ;
2179
- }
2173
+ Py_hash_t hash = _PyObject_HashFast (key );
2174
+ if (hash == -1 ) {
2175
+ PyErr_FormatUnraisable (warnmsg );
2176
+ return NULL ;
2180
2177
}
2181
2178
2182
2179
PyThreadState * tstate = _PyThreadState_GET ();
@@ -2225,12 +2222,9 @@ _PyDict_LookupIndex(PyDictObject *mp, PyObject *key)
2225
2222
assert (PyDict_CheckExact ((PyObject * )mp ));
2226
2223
assert (PyUnicode_CheckExact (key ));
2227
2224
2228
- Py_hash_t hash = unicode_get_hash (key );
2225
+ Py_hash_t hash = _PyObject_HashFast (key );
2229
2226
if (hash == -1 ) {
2230
- hash = PyObject_Hash (key );
2231
- if (hash == -1 ) {
2232
- return -1 ;
2233
- }
2227
+ return -1 ;
2234
2228
}
2235
2229
2236
2230
return _Py_dict_lookup (mp , key , hash , & value );
@@ -2301,14 +2295,10 @@ PyDict_GetItemRef(PyObject *op, PyObject *key, PyObject **result)
2301
2295
return -1 ;
2302
2296
}
2303
2297
2304
- Py_hash_t hash ;
2305
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 )
2306
- {
2307
- hash = PyObject_Hash (key );
2308
- if (hash == -1 ) {
2309
- * result = NULL ;
2310
- return -1 ;
2311
- }
2298
+ Py_hash_t hash = _PyObject_HashFast (key );
2299
+ if (hash == -1 ) {
2300
+ * result = NULL ;
2301
+ return -1 ;
2312
2302
}
2313
2303
2314
2304
return _PyDict_GetItemRef_KnownHash ((PyDictObject * )op , key , hash , result );
@@ -2320,13 +2310,10 @@ _PyDict_GetItemRef_Unicode_LockHeld(PyDictObject *op, PyObject *key, PyObject **
2320
2310
ASSERT_DICT_LOCKED (op );
2321
2311
assert (PyUnicode_CheckExact (key ));
2322
2312
2323
- Py_hash_t hash ;
2324
- if ((hash = unicode_get_hash (key )) == -1 ) {
2325
- hash = PyObject_Hash (key );
2326
- if (hash == -1 ) {
2327
- * result = NULL ;
2328
- return -1 ;
2329
- }
2313
+ Py_hash_t hash = _PyObject_HashFast (key );
2314
+ if (hash == -1 ) {
2315
+ * result = NULL ;
2316
+ return -1 ;
2330
2317
}
2331
2318
2332
2319
PyObject * value ;
@@ -2360,12 +2347,9 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
2360
2347
PyErr_BadInternalCall ();
2361
2348
return NULL ;
2362
2349
}
2363
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 )
2364
- {
2365
- hash = PyObject_Hash (key );
2366
- if (hash == -1 ) {
2367
- return NULL ;
2368
- }
2350
+ hash = _PyObject_HashFast (key );
2351
+ if (hash == -1 ) {
2352
+ return NULL ;
2369
2353
}
2370
2354
2371
2355
#ifdef Py_GIL_DISABLED
@@ -2433,10 +2417,9 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key)
2433
2417
Py_hash_t hash ;
2434
2418
PyObject * value ;
2435
2419
2436
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2437
- hash = PyObject_Hash (key );
2438
- if (hash == -1 )
2439
- return NULL ;
2420
+ hash = _PyObject_HashFast (key );
2421
+ if (hash == -1 ) {
2422
+ return NULL ;
2440
2423
}
2441
2424
2442
2425
/* namespace 1: globals */
@@ -2461,14 +2444,11 @@ setitem_take2_lock_held(PyDictObject *mp, PyObject *key, PyObject *value)
2461
2444
assert (key );
2462
2445
assert (value );
2463
2446
assert (PyDict_Check (mp ));
2464
- Py_hash_t hash ;
2465
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2466
- hash = PyObject_Hash (key );
2467
- if (hash == -1 ) {
2468
- Py_DECREF (key );
2469
- Py_DECREF (value );
2470
- return -1 ;
2471
- }
2447
+ Py_hash_t hash = _PyObject_HashFast (key );
2448
+ if (hash == -1 ) {
2449
+ Py_DECREF (key );
2450
+ Py_DECREF (value );
2451
+ return -1 ;
2472
2452
}
2473
2453
2474
2454
PyInterpreterState * interp = _PyInterpreterState_GET ();
@@ -2617,12 +2597,10 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
2617
2597
int
2618
2598
PyDict_DelItem (PyObject * op , PyObject * key )
2619
2599
{
2620
- Py_hash_t hash ;
2621
2600
assert (key );
2622
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2623
- hash = PyObject_Hash (key );
2624
- if (hash == -1 )
2625
- return -1 ;
2601
+ Py_hash_t hash = _PyObject_HashFast (key );
2602
+ if (hash == -1 ) {
2603
+ return -1 ;
2626
2604
}
2627
2605
2628
2606
return _PyDict_DelItem_KnownHash (op , key , hash );
@@ -2946,15 +2924,12 @@ pop_lock_held(PyObject *op, PyObject *key, PyObject **result)
2946
2924
return 0 ;
2947
2925
}
2948
2926
2949
- Py_hash_t hash ;
2950
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2951
- hash = PyObject_Hash (key );
2952
- if (hash == -1 ) {
2953
- if (result ) {
2954
- * result = NULL ;
2955
- }
2956
- return -1 ;
2927
+ Py_hash_t hash = _PyObject_HashFast (key );
2928
+ if (hash == -1 ) {
2929
+ if (result ) {
2930
+ * result = NULL ;
2957
2931
}
2932
+ return -1 ;
2958
2933
}
2959
2934
return _PyDict_Pop_KnownHash (dict , key , hash , result );
2960
2935
}
@@ -3285,10 +3260,9 @@ dict_subscript(PyObject *self, PyObject *key)
3285
3260
Py_hash_t hash ;
3286
3261
PyObject * value ;
3287
3262
3288
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
3289
- hash = PyObject_Hash (key );
3290
- if (hash == -1 )
3291
- return NULL ;
3263
+ hash = _PyObject_HashFast (key );
3264
+ if (hash == -1 ) {
3265
+ return NULL ;
3292
3266
}
3293
3267
ix = _Py_dict_lookup_threadsafe (mp , key , hash , & value );
3294
3268
if (ix == DKIX_ERROR )
@@ -4172,10 +4146,9 @@ dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value)
4172
4146
Py_hash_t hash ;
4173
4147
Py_ssize_t ix ;
4174
4148
4175
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4176
- hash = PyObject_Hash (key );
4177
- if (hash == -1 )
4178
- return NULL ;
4149
+ hash = _PyObject_HashFast (key );
4150
+ if (hash == -1 ) {
4151
+ return NULL ;
4179
4152
}
4180
4153
ix = _Py_dict_lookup_threadsafe (self , key , hash , & val );
4181
4154
if (ix == DKIX_ERROR )
@@ -4205,14 +4178,12 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
4205
4178
return -1 ;
4206
4179
}
4207
4180
4208
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4209
- hash = PyObject_Hash (key );
4210
- if (hash == -1 ) {
4211
- if (result ) {
4212
- * result = NULL ;
4213
- }
4214
- return -1 ;
4181
+ hash = _PyObject_HashFast (key );
4182
+ if (hash == -1 ) {
4183
+ if (result ) {
4184
+ * result = NULL ;
4215
4185
}
4186
+ return -1 ;
4216
4187
}
4217
4188
4218
4189
if (mp -> ma_keys == Py_EMPTY_KEYS ) {
@@ -4642,12 +4613,10 @@ static PyMethodDef mapp_methods[] = {
4642
4613
int
4643
4614
PyDict_Contains (PyObject * op , PyObject * key )
4644
4615
{
4645
- Py_hash_t hash ;
4616
+ Py_hash_t hash = _PyObject_HashFast ( key ) ;
4646
4617
4647
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4648
- hash = PyObject_Hash (key );
4649
- if (hash == -1 )
4650
- return -1 ;
4618
+ if (hash == -1 ) {
4619
+ return -1 ;
4651
4620
}
4652
4621
4653
4622
return _PyDict_Contains_KnownHash (op , key , hash );
@@ -6727,11 +6696,9 @@ int
6727
6696
_PyDict_SetItem_LockHeld (PyDictObject * dict , PyObject * name , PyObject * value )
6728
6697
{
6729
6698
if (value == NULL ) {
6730
- Py_hash_t hash ;
6731
- if (!PyUnicode_CheckExact (name ) || (hash = unicode_get_hash (name )) == -1 ) {
6732
- hash = PyObject_Hash (name );
6733
- if (hash == -1 )
6734
- return -1 ;
6699
+ Py_hash_t hash = _PyObject_HashFast (name );
6700
+ if (hash == -1 ) {
6701
+ return -1 ;
6735
6702
}
6736
6703
return delitem_knownhash_lock_held ((PyObject * )dict , name , hash );
6737
6704
} else {
0 commit comments