arrayvec icon indicating copy to clipboard operation
arrayvec copied to clipboard

Make `ArrayString::try_push(c: char)` smarter

Open StackOverflowExcept1on opened this issue 2 years ago • 0 comments

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 avatar Dec 04 '23 12:12 StackOverflowExcept1on