Skip to content

String insertion #584

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: main
Choose a base branch
from

Conversation

riley-williams
Copy link
Contributor

Basically just copies the implementations of insert and insert_str from std::String with minor modification.

Comment on lines +732 to +735
let mut buf = [0u8; 4];
let encoded = ch.encode_utf8(&mut buf);
core::ptr::copy_nonoverlapping(
encoded.as_ptr(),
self.vec.as_mut_ptr().add(idx),
ch_len,
);
Copy link
Contributor Author

@riley-williams riley-williams Jul 14, 2025

Choose a reason for hiding this comment

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

This differs from the std::String implementation which uses an unstable method to encode directly into the destination buffer.

core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(idx));

There's probably a better way than what I've done here.

@riley-williams
Copy link
Contributor Author

Failing because of some existing clippy issues, opened a separate PR to fix them: #585

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