Skip to content

Commit ddd73c8

Browse files
jgarzikclaude
andcommitted
Replace magic numbers with named constants in set repr iteration
Use SET_ENTRY_SIZE, SET_ENTRY_KEY, SET_ENTRY_KEY_TAG, SET_TOMBSTONE constants instead of hardcoded 24, 8, 16, 0xDEAD in set_repr loop. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 68dc6a9 commit ddd73c8

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/repr.asm

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
%include "types.inc"
1313

1414

15+
; Set entry layout (must match set.asm)
16+
SET_ENTRY_HASH equ 0
17+
SET_ENTRY_KEY equ 8
18+
SET_ENTRY_KEY_TAG equ 16
19+
SET_ENTRY_SIZE equ 24
20+
SET_TOMBSTONE equ 0xDEAD
21+
1522
extern ap_malloc
1623
extern ap_free
1724
extern ap_realloc
@@ -455,14 +462,14 @@ DEF_FUNC set_repr, 24
455462
cmp r12, r13
456463
jge .sr_done
457464

458-
; SetEntry is 24 bytes: hash(8) + key(8) + key_tag(8)
465+
; SetEntry is SET_ENTRY_SIZE bytes: hash(8) + key(8) + key_tag(8)
459466
mov rax, [rbx + PyDictObject.entries]
460-
imul rcx, r12, 24 ; index * SET_ENTRY_SIZE (24)
461-
cmp qword [rax + rcx + 16], 0 ; key_tag == TAG_NULL → empty
467+
imul rcx, r12, SET_ENTRY_SIZE
468+
cmp qword [rax + rcx + SET_ENTRY_KEY_TAG], 0 ; empty
462469
je .sr_next
463-
cmp qword [rax + rcx + 16], 0xDEAD ; key_tag == TOMBSTONE → deleted
470+
cmp qword [rax + rcx + SET_ENTRY_KEY_TAG], SET_TOMBSTONE ; deleted
464471
je .sr_next
465-
mov rdi, [rax + rcx + 8] ; key payload (only if occupied)
472+
mov rdi, [rax + rcx + SET_ENTRY_KEY] ; key payload
466473

467474
; Print separator if not first
468475
test r14, r14

0 commit comments

Comments
 (0)