Skip to content

Commit cc0a356

Browse files
address pr comments
1 parent 270837b commit cc0a356

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Include/internal/pycore_dict.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,18 @@ struct _dictkeysobject {
198198
/* Number of used entries in dk_entries. */
199199
Py_ssize_t dk_nentries;
200200

201-
/* Actual hash table of dk_size entries. It holds indices in dk_entries,
202-
or DKIX_EMPTY(-1) or DKIX_DUMMY(-2).
201+
/* Offset to entries within this allocation.
202+
203+
PyDictKeysObject * points to dk_refcnt. The actual hash table
204+
(dk_indices) is stored immediately before the struct in memory;
205+
see _DK_INDICES_END() and _DK_INDICES_BASE().
206+
207+
dk_indices marks the start of the entries array and is used by
208+
DK_ENTRIES() / DK_UNICODE_ENTRIES(). */
209+
char dk_indices[]; /* char is required to avoid strict aliasing. */
210+
211+
/* dk_indices is the actual hash table of dk_size entries. It holds
212+
indices in dk_entries, or DKIX_EMPTY(-1) or DKIX_DUMMY(-2).
203213
204214
Indices must be: 0 <= indice < USABLE_FRACTION(dk_size).
205215
@@ -211,10 +221,6 @@ struct _dictkeysobject {
211221
- 8 bytes otherwise (int64_t*)
212222
213223
Dynamically sized, SIZEOF_VOID_P is minimum. */
214-
char dk_indices[]; /* char is required to avoid strict aliasing. */
215-
216-
/* "PyDictKeyEntry or PyDictUnicodeEntry dk_entries[USABLE_FRACTION(DK_SIZE(dk))];" array follows:
217-
see the DK_ENTRIES() / DK_UNICODE_ENTRIES() functions below */
218224
};
219225

220226
/* This must be no more than 250, for the prefix size to fit in one byte. */

Objects/dictobject.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ As of Python 3.6, this is compact and ordered. Basic idea is described here:
1616
1717
layout:
1818
19+
+---------------------+
20+
| dk_indices[] |
21+
| |
22+
+---------------------+
1923
| dk_refcnt |
2024
| dk_log2_size |
2125
| dk_log2_index_bytes |
@@ -24,13 +28,16 @@ As of Python 3.6, this is compact and ordered. Basic idea is described here:
2428
| dk_usable |
2529
| dk_nentries |
2630
+---------------------+
27-
| dk_indices[] |
28-
| |
29-
+---------------------+
3031
| dk_entries[] |
3132
| |
3233
+---------------------+
3334
35+
PyDictKeysObject * points to the start of the struct (dk_refcnt). The
36+
dk_indices table is stored immediately before this struct in memory.
37+
38+
NOTE: dk_mutex is present in free-threaded builds, in between dk_kind and
39+
dk_version.
40+
3441
dk_indices is actual hashtable. It holds index in entries, or DKIX_EMPTY(-1)
3542
or DKIX_DUMMY(-2).
3643
Size of indices is dk_size. Type of each index in indices varies with dk_size:

0 commit comments

Comments
 (0)