@@ -115,19 +115,20 @@ As a consequence of this, split keys have a maximum size of 16.
115
115
#define PyDict_MINSIZE 8
116
116
117
117
#include "Python.h"
118
- #include "pycore_bitutils.h" // _Py_bit_length
119
- #include "pycore_call.h" // _PyObject_CallNoArgs()
120
- #include "pycore_ceval.h" // _PyEval_GetBuiltin()
121
- #include "pycore_code.h" // stats
122
- #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION, Py_END_CRITICAL_SECTION
123
- #include "pycore_dict.h" // export _PyDict_SizeOf()
124
- #include "pycore_freelist.h" // _PyFreeListState_GET()
125
- #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
126
- #include "pycore_object.h" // _PyObject_GC_TRACK(), _PyDebugAllocatorStats()
127
- #include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
128
- #include "pycore_pystate.h" // _PyThreadState_GET()
129
- #include "pycore_setobject.h" // _PySet_NextEntry()
130
- #include "stringlib/eq.h" // unicode_eq()
118
+ #include "pycore_bitutils.h" // _Py_bit_length
119
+ #include "pycore_call.h" // _PyObject_CallNoArgs()
120
+ #include "pycore_ceval.h" // _PyEval_GetBuiltin()
121
+ #include "pycore_code.h" // stats
122
+ #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION, Py_END_CRITICAL_SECTION
123
+ #include "pycore_dict.h" // export _PyDict_SizeOf()
124
+ #include "pycore_freelist.h" // _PyFreeListState_GET()
125
+ #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
126
+ #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_PTR_RELAXED
127
+ #include "pycore_object.h" // _PyObject_GC_TRACK(), _PyDebugAllocatorStats()
128
+ #include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
129
+ #include "pycore_pystate.h" // _PyThreadState_GET()
130
+ #include "pycore_setobject.h" // _PySet_NextEntry()
131
+ #include "stringlib/eq.h" // unicode_eq
131
132
132
133
#include <stdbool.h>
133
134
@@ -234,6 +235,13 @@ set_values(PyDictObject *mp, PyDictValues *values)
234
235
235
236
#endif
236
237
238
+ #define STORE_KEY (ep , key ) FT_ATOMIC_STORE_PTR_RELAXED(ep->me_key, key)
239
+ #define STORE_VALUE (ep , value ) FT_ATOMIC_STORE_PTR_RELAXED(ep->me_value, value)
240
+ #define STORE_SPLIT_VALUE (mp , idx , value ) FT_ATOMIC_STORE_PTR_RELAXED(mp->ma_values->values[idx], value)
241
+ #define STORE_HASH (ep , hash ) FT_ATOMIC_STORE_SSIZE_RELAXED(ep->me_hash, hash)
242
+ #define STORE_KEYS_USABLE (keys , usable ) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_usable, usable)
243
+ #define STORE_KEYS_NENTRIES (keys , nentries ) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_nentries, nentries)
244
+
237
245
#define PERTURB_SHIFT 5
238
246
239
247
/*
@@ -1605,7 +1613,6 @@ insert_into_splitdictkeys(PyDictKeysObject *keys, PyObject *name)
1605
1613
return ix ;
1606
1614
}
1607
1615
1608
-
1609
1616
static inline int
1610
1617
insert_combined_dict (PyInterpreterState * interp , PyDictObject * mp ,
1611
1618
Py_hash_t hash , PyObject * key , PyObject * value )
@@ -1623,18 +1630,18 @@ insert_combined_dict(PyInterpreterState *interp, PyDictObject *mp,
1623
1630
if (DK_IS_UNICODE (mp -> ma_keys )) {
1624
1631
PyDictUnicodeEntry * ep ;
1625
1632
ep = & DK_UNICODE_ENTRIES (mp -> ma_keys )[mp -> ma_keys -> dk_nentries ];
1626
- ep -> me_key = key ;
1627
- ep -> me_value = value ;
1633
+ STORE_KEY ( ep , key ) ;
1634
+ STORE_VALUE ( ep , value ) ;
1628
1635
}
1629
1636
else {
1630
1637
PyDictKeyEntry * ep ;
1631
1638
ep = & DK_ENTRIES (mp -> ma_keys )[mp -> ma_keys -> dk_nentries ];
1632
- ep -> me_key = key ;
1633
- ep -> me_hash = hash ;
1634
- ep -> me_value = value ;
1639
+ STORE_KEY ( ep , key ) ;
1640
+ STORE_VALUE ( ep , value ) ;
1641
+ STORE_HASH ( ep , hash ) ;
1635
1642
}
1636
- mp -> ma_keys -> dk_usable -- ;
1637
- mp -> ma_keys -> dk_nentries ++ ;
1643
+ STORE_KEYS_USABLE ( mp -> ma_keys , mp -> ma_keys -> dk_usable - 1 ) ;
1644
+ STORE_KEYS_NENTRIES ( mp -> ma_keys , mp -> ma_keys -> dk_nentries + 1 ) ;
1638
1645
assert (mp -> ma_keys -> dk_usable >= 0 );
1639
1646
return 0 ;
1640
1647
}
@@ -1666,7 +1673,7 @@ insert_split_dict(PyInterpreterState *interp, PyDictObject *mp,
1666
1673
Py_ssize_t index = keys -> dk_nentries ;
1667
1674
_PyDictValues_AddToInsertionOrder (mp -> ma_values , index );
1668
1675
assert (mp -> ma_values -> values [index ] == NULL );
1669
- mp -> ma_values -> values [ index ] = value ;
1676
+ STORE_SPLIT_VALUE ( mp , index , value ) ;
1670
1677
1671
1678
split_keys_entry_added (keys );
1672
1679
assert (keys -> dk_usable >= 0 );
@@ -2491,15 +2498,15 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
2491
2498
if (DK_IS_UNICODE (mp -> ma_keys )) {
2492
2499
PyDictUnicodeEntry * ep = & DK_UNICODE_ENTRIES (mp -> ma_keys )[ix ];
2493
2500
old_key = ep -> me_key ;
2494
- ep -> me_key = NULL ;
2495
- ep -> me_value = NULL ;
2501
+ STORE_KEY ( ep , NULL ) ;
2502
+ STORE_VALUE ( ep , NULL ) ;
2496
2503
}
2497
2504
else {
2498
2505
PyDictKeyEntry * ep = & DK_ENTRIES (mp -> ma_keys )[ix ];
2499
2506
old_key = ep -> me_key ;
2500
- ep -> me_key = NULL ;
2501
- ep -> me_value = NULL ;
2502
- ep -> me_hash = 0 ;
2507
+ STORE_KEY ( ep , NULL ) ;
2508
+ STORE_VALUE ( ep , NULL ) ;
2509
+ STORE_HASH ( ep , 0 ) ;
2503
2510
}
2504
2511
Py_DECREF (old_key );
2505
2512
}
0 commit comments