Skip to content

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

@StackOverflowExcept1on

Description

@StackOverflowExcept1on

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()),
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions