Skip to content

version_types.py: cache ClosedOpenRange __str__ and __hash__#51832

Merged
becker33 merged 2 commits intodevelopfrom
hs/fix/closed-open-range-cache-str-hash
Jan 11, 2026
Merged

version_types.py: cache ClosedOpenRange __str__ and __hash__#51832
becker33 merged 2 commits intodevelopfrom
hs/fix/closed-open-range-cache-str-hash

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Jan 9, 2026

Since ClosedOpenRange is immutable we can cache its string
and hash value in the named constructor, before the internal
representation of hi = _next_version(hi) is computed.

That saves the expensive, allocating _prev_version call in
__str__ and reduces "setup time" by 7.4%.

Should be the best of both worlds: the internal _next_version
representation allowed us to do non-allocating, fast range inclusion
checks as tuple comparsion, while this change ensures that __str__
doesn't have to compute the original hi from the input.

comparison

Since ClosedOpenRange is immutable we can cache its string
representation and hash value.

That saves the expensive `_prev_version` call.

Signed-off-by: Harmen Stoppels <[email protected]>
@haampie haampie force-pushed the hs/fix/closed-open-range-cache-str-hash branch from 68a8d23 to ff6e898 Compare January 9, 2026 20:42
Signed-off-by: Harmen Stoppels <[email protected]>
@becker33 becker33 merged commit 505097e into develop Jan 11, 2026
31 of 32 checks passed
@becker33 becker33 deleted the hs/fix/closed-open-range-cache-str-hash branch January 11, 2026 05:11
@haampie haampie mentioned this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants