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

Make ArrayString::try_push(c: char) smarter #252

Open
StackOverflowExcept1on opened this issue Dec 4, 2023 · 0 comments
Open

Make ArrayString::try_push(c: char) smarter #252

StackOverflowExcept1on opened this issue Dec 4, 2023 · 0 comments

Comments

@StackOverflowExcept1on
Copy link

Currently it encodes the character to utf8 in anyway instead of memcpy for ascii characters. Although String::push has some optimizations.

https://doc.rust-lang.org/std/string/struct.String.html#method.push

    pub fn push(&mut self, ch: char) {
        match ch.len_utf8() {
            1 => self.vec.push(ch as u8),
            _ => self.vec.extend_from_slice(ch.encode_utf8(&mut [0; 4]).as_bytes()),
        }
    }
@StackOverflowExcept1on StackOverflowExcept1on changed the title Make ArrayString::push(c: char) smarter Make ArrayString::try_push(c: char) smarter Dec 4, 2023
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

No branches or pull requests

1 participant