Skip to content

Add custom allocator support - #592

Open
bolshoytoster wants to merge 4 commits into
servo:v2from
bolshoytoster:v2
Open

Add custom allocator support#592
bolshoytoster wants to merge 4 commits into
servo:v2from
bolshoytoster:v2

Conversation

@bolshoytoster

@bolshoytoster bolshoytoster commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Closes #55.

This doesn't add support in the following APIs:
From
from_elem
Default
from_buf
from_buf_and_len
from_buf_and_len_unchecked
from_vec
from_raw_parts
splice
from_slice_copy
FromIterator

new, try_with_capacity and with_capacity now have _in counterparts, to match the standard library.

PartialEq does not support comparing two SmallVecs with different allocators (this is different from std Vec). This shouldn't matter too much, since you can just compare them as slices instead.

You also can't append two SmallVecs with different allocators, this matches std Vec.

@bolshoytoster

Copy link
Copy Markdown
Contributor Author

I'm not really sure how to read the fuzz failure. It looks like one of the tests times out, but I can't seem to install honggfuzz locally to test (TRUE being undefined in a c file)

@fereidani

Copy link
Copy Markdown
Contributor

Try to rerun the CI with a force push: git commit --amend --no-edit && git push --force

Really should've done this from the start, but I suppose this might make it easier to review
@bolshoytoster

Copy link
Copy Markdown
Contributor Author

Oh it might be due to a change I made to grow. It used to be able to shrink allocations if new_capacity < old_capacity, but since the allocator API has separate grow and shrink functions (no realloc), I split it into two matching functions, and grow now panics if you give it a smaller capacity.

Should I revert the behaviour and just have a if new_capacity < old_capacity { /*shrink*/ } else { /*grow*/ }?

@fereidani

Copy link
Copy Markdown
Contributor

I'm a contributor like you, I think project members should comment on it.
But as your PR title is about custom allocator support, I would suggest to keep it as minimal as possible and direct to the point without no extra behavior changes.
Then check rust-lang/rust alloc behavior if smallvec does not behave the same, send another PR and fix that issue separately.

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.

Support parametric allocators

2 participants