Skip to content

Rework specialization #384

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

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open

Rework specialization #384

wants to merge 2 commits into from

Conversation

TDecking
Copy link
Contributor

@TDecking TDecking commented Jun 2, 2025

This ports most of the specialization work done for the Vec Rust type to this library. With that the extend, from, and extend_from_slice are now specialized, with specialization triggering in more instances. This also extends to other functions such as from_elem and clone_from which were not specialized before.

This also adds some missing trait implementations and functions with trait bounds.

All of this should finish one of the items in #183. Note that extend_from_slice has not been removed, since Vec
also has this function. Instead, its trait bound was relaxed from Copy to Clone for a matching signature.

@TDecking TDecking force-pushed the spec branch 3 times, most recently from f676145 to 44eb023 Compare June 5, 2025 20:48
@mbrubeck
Copy link
Collaborator

mbrubeck commented Jun 6, 2025

I'm not sure we should make the exact same API decisions as the standard library here.

Because of the standard library's special status, it can use specialization internally even with the stable toolchain. However, smallvec cannot do the same. We should expect (and recommend) that most users of this crate will not have the specialization feature enabled. But they still may need access to the specially-optimized versions of these functions when applicable.

Therefore, I think we might want to continue offering optimized Copy-only functions like the current from_slice and extend_from_slice (though possibly not under the same name, since we should also provide the less-specialized version that matches the std::vec name and signature).

@TDecking
Copy link
Contributor Author

TDecking commented Jun 7, 2025

@mbrubeck I've added some Copy-only functions back. They have a _copy suffix in order to distinguish them from the others.

@mbrubeck
Copy link
Collaborator

Thanks. I will try to finish reviewing this soon.

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