Skip to content

[mypyc] Add librt.strings.isdigit codepoint primitive#21504

Merged
p-sawicki merged 1 commit into
python:masterfrom
VaggelisD:librt-strings-isdigit
May 18, 2026
Merged

[mypyc] Add librt.strings.isdigit codepoint primitive#21504
p-sawicki merged 1 commit into
python:masterfrom
VaggelisD:librt-strings-isdigit

Conversation

@VaggelisD
Copy link
Copy Markdown
Contributor

2nd PR building #21418

Wraps Py_UNICODE_ISDIGIT for the codepoint fast path, mirroring the already-merged librt.strings.isspace.

I've microbenchmarked both codepoint primitives and they're ~1.6x faster than their counterpart str specialized primitives.

Wraps `Py_UNICODE_ISDIGIT` for the codepoint fast path, mirroring the
already-merged `librt.strings.isspace` (python#21462).

Microbenchmark on a 12 KB SQL fragment: mypyc-compiled
`s[i].isdigit()` takes 0.070 ms; the codepoint path
`c: i32 = i32(ord(s[i])); isdigit(c)` takes 0.044 ms, roughly 1.6x
faster.
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Collaborator

@p-sawicki p-sawicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@p-sawicki p-sawicki merged commit d9f17fb into python:master May 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants