Remove the internal TOMLChar wrapper#492
Open
tfoutrein wants to merge 1 commit into
Open
Conversation
b4509b9 to
1c43d4d
Compare
After the bulk run-scans, the parser only built a `TOMLChar` (a `str` subclass) at run boundaries and used a handful of its `is_*()` helpers. Drop the class entirely: `Source` now yields plain `str` characters and detects end-of-input positionally (`_idx >= len` / `Source.end()`) instead of an identity sentinel, and the remaining character-class checks use module-level frozensets. A real NUL byte is still rejected as an invalid control char and is never mistaken for end-of-input, since EOF is now positional rather than a sentinel comparison. No behaviour change (972 tests incl. the toml-test conformance submodule; plus an 11.5k-input adversarial differential over EOF/truncation, real-NUL placement, empty/whitespace and structural fuzz — output and error-type byte-identical to master). Removes the per-character object construction and method dispatch (~1.1-1.18x over the previous step).
1c43d4d to
d92e0a0
Compare
Contributor
Author
|
Rebased onto |
frostming
reviewed
Jun 11, 2026
Comment on lines
+61
to
+65
| _SPACES = " \t" | ||
| _NL = "\n\r" | ||
| _WS = _SPACES + _NL | ||
| _BARE = string.ascii_letters + string.digits + "-_" | ||
| _KV = "= \t" |
Contributor
There was a problem hiding this comment.
Can we only keep the *_SET variants?All __contains__ check should work, too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
After the bulk run-scans (#490/#491), the parser only constructs a
TOMLChar(astrsubclass) at run boundaries and uses a handful of itsis_*()helpers. This removes the class entirely:Sourceyields plainstrcharacters;inc()/advance_*readself[i]directly._idx >= len/Source.end()) instead of an identity sentinel.A real NUL byte is still rejected as an invalid control char and is never mistaken for end-of-input, since EOF is now positional rather than a value/identity comparison.
Benchmarks
Median, interleaved A/B vs
master(includes #489–#491):The removal itself adds ~1.1–1.18× over #491. No regression on any shape.
Tests
Full suite passes (972, incl. the toml-test conformance submodule). On top of that, an 11.5k-input adversarial differential — EOF/truncation at every prefix length, real-NUL placement in every position, empty/whitespace/BOM, and structural fuzz — is byte-identical in output and exception type to
master. No public API change (TOMLCharwas not exported).