Skip to content

Commit bc7ef53

Browse files
Coerce the column type to int once in encode_row_header
The validation loop called ``int(t)`` twice per column — once for the nibble-range bound check and again for the ``_VALID_TYPE_CODES`` membership probe. On multi-thousand-column headers the doubled coercion adds Python-level overhead with no behavioural benefit. Pull the coercion to a local; both error diagnostics are preserved. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 98453d4 commit bc7ef53

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/dqlitewire/tuples.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,15 @@ def encode_row_header(types: Sequence[ValueType]) -> bytes:
306306
return b""
307307

308308
for i, t in enumerate(types):
309-
if int(t) > 15:
309+
# Coerce once. The prior shape called ``int(t)`` twice per
310+
# column (once for the nibble-range check, once for the
311+
# membership probe); on multi-thousand-column headers the
312+
# doubled coercion adds measurable Python-level overhead.
313+
code = int(t)
314+
if code > 15:
310315
raise EncodeError(f"Value type {t} at index {i} exceeds 4-bit nibble range (max 15)")
311-
if int(t) not in _VALID_TYPE_CODES:
312-
raise EncodeError(f"Invalid type code {int(t)} at index {i}: not a valid ValueType")
316+
if code not in _VALID_TYPE_CODES:
317+
raise EncodeError(f"Invalid type code {code} at index {i}: not a valid ValueType")
313318

314319
header = bytearray()
315320
for i in range(0, len(types), 2):

0 commit comments

Comments
 (0)