Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove more allocations #180

Merged
merged 2 commits into from
Dec 29, 2024
Merged

remove more allocations #180

merged 2 commits into from
Dec 29, 2024

Conversation

BurntSushi
Copy link
Owner

This continues work from #179 to make progress on #168.

I did this to get a sense for how much `jiff::fmt` depends on `alloc`.
It actually looks pretty good. Most uses of `alloc` are just for
convenience `String` APIs.

The one hiccup is `strtime` where it uses `String` for IANA time zone
names and time zone abbreviations. I think I can use a small fixed size
array for time zone abbreviations, but that might be harder to get away
with for IANA names. With that said, I'm not planning to really support
IANA time zones in core-only mode, so we can probably just `cfg`
ourselves out of that problem for the most part.
This removes yet another needless but harmless allocation in pursuit of
progress on #168.

In this case, returning a `&str` is part of the public API when a time
zone is a fixed offset, so we do need to store the offset as a string
somewhere. Thankfully, it's pretty small (smaller than a `Box<str>`) and
there's a predictable maximum length on the string. So it's not a big
deal to just generate the string on the stack and store it in the
`TimeZone` for this case.
@BurntSushi BurntSushi merged commit 396fdcf into master Dec 29, 2024
17 checks passed
@BurntSushi BurntSushi deleted the ag/reduce-alloc2 branch December 29, 2024 17:23
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.

1 participant