@@ -433,7 +433,7 @@ static inline Py_hash_t
433
433
unicode_get_hash (PyObject * o )
434
434
{
435
435
assert (PyUnicode_CheckExact (o ));
436
- return _PyASCIIObject_CAST (o )-> hash ;
436
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyASCIIObject_CAST (o )-> hash ) ;
437
437
}
438
438
439
439
/* Print summary info about the state of the optimized allocator */
@@ -2177,13 +2177,10 @@ dict_getitem(PyObject *op, PyObject *key, const char *warnmsg)
2177
2177
}
2178
2178
PyDictObject * mp = (PyDictObject * )op ;
2179
2179
2180
- Py_hash_t hash ;
2181
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2182
- hash = PyObject_Hash (key );
2183
- if (hash == -1 ) {
2184
- PyErr_FormatUnraisable (warnmsg );
2185
- return NULL ;
2186
- }
2180
+ Py_hash_t hash = _PyObject_HashFast (key );
2181
+ if (hash == -1 ) {
2182
+ PyErr_FormatUnraisable (warnmsg );
2183
+ return NULL ;
2187
2184
}
2188
2185
2189
2186
PyThreadState * tstate = _PyThreadState_GET ();
@@ -2232,12 +2229,9 @@ _PyDict_LookupIndex(PyDictObject *mp, PyObject *key)
2232
2229
assert (PyDict_CheckExact ((PyObject * )mp ));
2233
2230
assert (PyUnicode_CheckExact (key ));
2234
2231
2235
- Py_hash_t hash = unicode_get_hash (key );
2232
+ Py_hash_t hash = _PyObject_HashFast (key );
2236
2233
if (hash == -1 ) {
2237
- hash = PyObject_Hash (key );
2238
- if (hash == -1 ) {
2239
- return -1 ;
2240
- }
2234
+ return -1 ;
2241
2235
}
2242
2236
2243
2237
return _Py_dict_lookup (mp , key , hash , & value );
@@ -2308,14 +2302,10 @@ PyDict_GetItemRef(PyObject *op, PyObject *key, PyObject **result)
2308
2302
return -1 ;
2309
2303
}
2310
2304
2311
- Py_hash_t hash ;
2312
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 )
2313
- {
2314
- hash = PyObject_Hash (key );
2315
- if (hash == -1 ) {
2316
- * result = NULL ;
2317
- return -1 ;
2318
- }
2305
+ Py_hash_t hash = _PyObject_HashFast (key );
2306
+ if (hash == -1 ) {
2307
+ * result = NULL ;
2308
+ return -1 ;
2319
2309
}
2320
2310
2321
2311
return _PyDict_GetItemRef_KnownHash ((PyDictObject * )op , key , hash , result );
@@ -2327,13 +2317,10 @@ _PyDict_GetItemRef_Unicode_LockHeld(PyDictObject *op, PyObject *key, PyObject **
2327
2317
ASSERT_DICT_LOCKED (op );
2328
2318
assert (PyUnicode_CheckExact (key ));
2329
2319
2330
- Py_hash_t hash ;
2331
- if ((hash = unicode_get_hash (key )) == -1 ) {
2332
- hash = PyObject_Hash (key );
2333
- if (hash == -1 ) {
2334
- * result = NULL ;
2335
- return -1 ;
2336
- }
2320
+ Py_hash_t hash = _PyObject_HashFast (key );
2321
+ if (hash == -1 ) {
2322
+ * result = NULL ;
2323
+ return -1 ;
2337
2324
}
2338
2325
2339
2326
PyObject * value ;
@@ -2367,12 +2354,9 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
2367
2354
PyErr_BadInternalCall ();
2368
2355
return NULL ;
2369
2356
}
2370
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 )
2371
- {
2372
- hash = PyObject_Hash (key );
2373
- if (hash == -1 ) {
2374
- return NULL ;
2375
- }
2357
+ hash = _PyObject_HashFast (key );
2358
+ if (hash == -1 ) {
2359
+ return NULL ;
2376
2360
}
2377
2361
2378
2362
#ifdef Py_GIL_DISABLED
@@ -2440,10 +2424,9 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key)
2440
2424
Py_hash_t hash ;
2441
2425
PyObject * value ;
2442
2426
2443
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2444
- hash = PyObject_Hash (key );
2445
- if (hash == -1 )
2446
- return NULL ;
2427
+ hash = _PyObject_HashFast (key );
2428
+ if (hash == -1 ) {
2429
+ return NULL ;
2447
2430
}
2448
2431
2449
2432
/* namespace 1: globals */
@@ -2468,14 +2451,11 @@ setitem_take2_lock_held(PyDictObject *mp, PyObject *key, PyObject *value)
2468
2451
assert (key );
2469
2452
assert (value );
2470
2453
assert (PyDict_Check (mp ));
2471
- Py_hash_t hash ;
2472
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2473
- hash = PyObject_Hash (key );
2474
- if (hash == -1 ) {
2475
- Py_DECREF (key );
2476
- Py_DECREF (value );
2477
- return -1 ;
2478
- }
2454
+ Py_hash_t hash = _PyObject_HashFast (key );
2455
+ if (hash == -1 ) {
2456
+ Py_DECREF (key );
2457
+ Py_DECREF (value );
2458
+ return -1 ;
2479
2459
}
2480
2460
2481
2461
PyInterpreterState * interp = _PyInterpreterState_GET ();
@@ -2624,12 +2604,10 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
2624
2604
int
2625
2605
PyDict_DelItem (PyObject * op , PyObject * key )
2626
2606
{
2627
- Py_hash_t hash ;
2628
2607
assert (key );
2629
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2630
- hash = PyObject_Hash (key );
2631
- if (hash == -1 )
2632
- return -1 ;
2608
+ Py_hash_t hash = _PyObject_HashFast (key );
2609
+ if (hash == -1 ) {
2610
+ return -1 ;
2633
2611
}
2634
2612
2635
2613
return _PyDict_DelItem_KnownHash (op , key , hash );
@@ -2953,15 +2931,12 @@ pop_lock_held(PyObject *op, PyObject *key, PyObject **result)
2953
2931
return 0 ;
2954
2932
}
2955
2933
2956
- Py_hash_t hash ;
2957
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
2958
- hash = PyObject_Hash (key );
2959
- if (hash == -1 ) {
2960
- if (result ) {
2961
- * result = NULL ;
2962
- }
2963
- return -1 ;
2934
+ Py_hash_t hash = _PyObject_HashFast (key );
2935
+ if (hash == -1 ) {
2936
+ if (result ) {
2937
+ * result = NULL ;
2964
2938
}
2939
+ return -1 ;
2965
2940
}
2966
2941
return _PyDict_Pop_KnownHash (dict , key , hash , result );
2967
2942
}
@@ -3293,10 +3268,9 @@ dict_subscript(PyObject *self, PyObject *key)
3293
3268
Py_hash_t hash ;
3294
3269
PyObject * value ;
3295
3270
3296
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
3297
- hash = PyObject_Hash (key );
3298
- if (hash == -1 )
3299
- return NULL ;
3271
+ hash = _PyObject_HashFast (key );
3272
+ if (hash == -1 ) {
3273
+ return NULL ;
3300
3274
}
3301
3275
ix = _Py_dict_lookup_threadsafe (mp , key , hash , & value );
3302
3276
if (ix == DKIX_ERROR )
@@ -4183,10 +4157,9 @@ dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value)
4183
4157
Py_hash_t hash ;
4184
4158
Py_ssize_t ix ;
4185
4159
4186
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4187
- hash = PyObject_Hash (key );
4188
- if (hash == -1 )
4189
- return NULL ;
4160
+ hash = _PyObject_HashFast (key );
4161
+ if (hash == -1 ) {
4162
+ return NULL ;
4190
4163
}
4191
4164
ix = _Py_dict_lookup_threadsafe (self , key , hash , & val );
4192
4165
if (ix == DKIX_ERROR )
@@ -4216,14 +4189,12 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
4216
4189
return -1 ;
4217
4190
}
4218
4191
4219
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4220
- hash = PyObject_Hash (key );
4221
- if (hash == -1 ) {
4222
- if (result ) {
4223
- * result = NULL ;
4224
- }
4225
- return -1 ;
4192
+ hash = _PyObject_HashFast (key );
4193
+ if (hash == -1 ) {
4194
+ if (result ) {
4195
+ * result = NULL ;
4226
4196
}
4197
+ return -1 ;
4227
4198
}
4228
4199
4229
4200
if (mp -> ma_keys == Py_EMPTY_KEYS ) {
@@ -4655,12 +4626,10 @@ static PyMethodDef mapp_methods[] = {
4655
4626
int
4656
4627
PyDict_Contains (PyObject * op , PyObject * key )
4657
4628
{
4658
- Py_hash_t hash ;
4629
+ Py_hash_t hash = _PyObject_HashFast ( key ) ;
4659
4630
4660
- if (!PyUnicode_CheckExact (key ) || (hash = unicode_get_hash (key )) == -1 ) {
4661
- hash = PyObject_Hash (key );
4662
- if (hash == -1 )
4663
- return -1 ;
4631
+ if (hash == -1 ) {
4632
+ return -1 ;
4664
4633
}
4665
4634
4666
4635
return _PyDict_Contains_KnownHash (op , key , hash );
@@ -6743,11 +6712,9 @@ int
6743
6712
_PyDict_SetItem_LockHeld (PyDictObject * dict , PyObject * name , PyObject * value )
6744
6713
{
6745
6714
if (value == NULL ) {
6746
- Py_hash_t hash ;
6747
- if (!PyUnicode_CheckExact (name ) || (hash = unicode_get_hash (name )) == -1 ) {
6748
- hash = PyObject_Hash (name );
6749
- if (hash == -1 )
6750
- return -1 ;
6715
+ Py_hash_t hash = _PyObject_HashFast (name );
6716
+ if (hash == -1 ) {
6717
+ return -1 ;
6751
6718
}
6752
6719
return delitem_knownhash_lock_held ((PyObject * )dict , name , hash );
6753
6720
} else {
0 commit comments