Skip to content

Commit 27b3fa0

Browse files
update layout comment per pr suggestion
1 parent 90dd9ae commit 27b3fa0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Include/internal/pycore_dict.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ typedef enum {
171171
DICT_KEYS_SPLIT = 2
172172
} DictKeysKind;
173173

174-
/* See dictobject.c for actual layout of DictKeysObject */
174+
/* See dictobject.c for the full DictKeysObject memory layout.
175+
* A PyDictKeysObject* points to the fixed-size header below.
176+
*/
175177
struct _dictkeysobject {
176178
Py_ssize_t dk_refcnt;
177179

@@ -211,7 +213,8 @@ struct _dictkeysobject {
211213
- 4 bytes if dk_size <= 0xffffffff (int32_t*)
212214
- 8 bytes otherwise (int64_t*)
213215
214-
Dynamically sized, SIZEOF_VOID_P is minimum. */
216+
Dynamically sized. This is the start of the variable-sized tail that
217+
immediately follows the fixed-size header. */
215218
char dk_indices[]; /* char is required to avoid strict aliasing. */
216219

217220
/* "PyDictKeyEntry or PyDictUnicodeEntry dk_entries[USABLE_FRACTION(DK_SIZE(dk))];" array follows:

Objects/dictobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ As of Python 3.6, this is compact and ordered. Basic idea is described here:
1717
layout:
1818
1919
+---------------------+
20+
| struct _dictkeysobj |
2021
| dk_refcnt |
2122
| dk_log2_size |
2223
| dk_log2_index_bytes |
@@ -25,13 +26,17 @@ As of Python 3.6, this is compact and ordered. Basic idea is described here:
2526
| dk_usable |
2627
| dk_nentries |
2728
+---------------------+
28-
| dk_indices[] |
29+
| dk_indices[] | <-- starts at &dk->dk_indices[0]
2930
| |
3031
+---------------------+
31-
| dk_entries[] |
32+
| dk_entries[] | <-- starts at DK_ENTRIES(dk)
3233
| |
3334
+---------------------+
3435
36+
A PyDictKeysObject* points to the start of the fixed-size header.
37+
The variable-sized part begins at dk_indices and is followed immediately by
38+
the entry array.
39+
3540
dk_indices is actual hashtable. It holds index in entries, or DKIX_EMPTY(-1)
3641
or DKIX_DUMMY(-2).
3742
Size of indices is dk_size. Type of each index in indices varies with dk_size:

0 commit comments

Comments
 (0)