Skip to content

[Geneva exporter] Optimize: Avoid temporary Vec in utf8_to_utf16le_bytes for Geneva exporter #305

Open
@lalitb

Description

@lalitb

utf8_to_utf16le_bytes creates a temporary vec which we can avoid. We don't need vec allocations for counting or serializing the utf-16 bytes. For example,

let meta_utf16_len = self.metadata.encode_utf16().count() * 2; // This would count without allocating


// This would serialize UTF-16LE bytes directly to a buffer

fn write_utf16le_to_buffer(buf: &mut Vec<u8>, s: &str) {
    for u in s.encode_utf16() {
        buf.extend_from_slice(&u.to_le_bytes());
    }
}

Originally posted by @utpilla in #261 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions