core: Skip UTF-8 validation in read_value()

The UTF-8 validation is very expensive. It's unclear if we ever need to
do it at read time and if we do, let's do it when we know the value is
actually going to be used. Speeds up read_value() a lot.
This commit is contained in:
Pekka Enberg
2024-01-27 09:45:28 +02:00
parent 2d625f34c5
commit bb56ba0736

View File

@@ -401,7 +401,8 @@ pub fn read_value(buf: &[u8], serial_type: &SerialType) -> Result<(Value, usize)
if buf.len() < n {
return Err(anyhow!("Invalid String value"));
}
let value = String::from_utf8(buf[0..n].to_vec())?;
let bytes = buf[0..n].to_vec();
let value = unsafe { String::from_utf8_unchecked(bytes) };
Ok((Value::Text(value), n))
}
}