MCPcopy Create free account
hub / github.com/apache/fory / write_latin1_string

Function write_latin1_string

rust/fory-core/src/util/string_util.rs:703–724  ·  view source on GitHub ↗
(writer: &mut Writer, s: &str)

Source from the content-addressed store, hash-verified

701
702 #[inline(always)]
703 pub fn write_latin1_string(writer: &mut Writer, s: &str) {
704 if s.len() < 128 {
705 // Fast path for small buffers
706 let bytes = s.as_bytes();
707 // CRITICAL: Only safe if ASCII (UTF-8 == Latin1 for ASCII)
708 let is_ascii = bytes.iter().all(|&b| b < 0x80);
709 if is_ascii {
710 writer.bf.reserve(s.len());
711 writer.bf.extend_from_slice(bytes);
712 } else {
713 // Non-ASCII: must iterate chars to extract Latin1 byte values
714 writer.bf.reserve(s.len());
715 for c in s.chars() {
716 let v = c as u32;
717 assert!(v <= 0xFF, "Non-Latin1 character found");
718 writer.bf.push(v as u8);
719 }
720 }
721 return;
722 }
723 write_latin1_simd(writer, s);
724 }
725
726 #[inline]
727 pub fn write_utf8_standard(writer: &mut Writer, s: &str) {

Callers 1

benchmark_read_latin1Function · 0.85

Calls 3

write_latin1_simdFunction · 0.85
lenMethod · 0.80
reserveMethod · 0.45

Tested by

no test coverage detected