Skip to content

Support for arena allocation via allocator_api2 (bumpalo) - #11

Open
luksan wants to merge 2 commits into
tomtomwombat:mainfrom
luksan:alloc_api2
Open

luksan wants to merge 2 commits into
tomtomwombat:mainfrom
luksan:alloc_api2

Conversation

@luksan

@luksan luksan commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

This add the type ArenaString which allocates long strings to an arena allocator instead of the global allocator.

The first commit adds infrastructure for using the Allocator trait, and the second adds the new string type.

Note that this does not add a phantom type parameter to Encoded for the allocator, to keep the diff smaller, but it means that there is no lifetime restriction in Encoded, allowing to get an Encoded with a longer lifetime than the allocator. Not an issue for the current code since that is handled correctly in the string types, but it could be worth adding if other use cases involving custom allocators are discovered.

Ignore the change to edition and resolver in Cargo.toml. Will remove that after review. (Just discovered I forgot that in there)

@tomtomwombat tomtomwombat left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok, the overall approach looks good so far. I'm curious if you had a use case for this? Should there be an ArenaArcString?

Comment thread cold-string/src/arena.rs
/// Deallocation happens by dropping the arena, which will free all strings allocated in it.
///
/// See [`ColdString`] for method documentation.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Extra space here

Comment thread cold-string/src/arena.rs
use std::string::String;
use bumpalo::Bump;

fn alloc_str<'a>(s: &str, arena: &'a Bump) -> ArenaString<'a> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what's the point of alloc_str wrapper?


impl<H> Encoded<H> {
#[inline]
pub(crate) fn new(s: &str, header: H) -> Self {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we move this to line 50 instead of a new impl block

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.

2 participants