From bb56ba07369f4e5d401fd5fb903fc1cc23115c69 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sat, 27 Jan 2024 09:45:28 +0200 Subject: [PATCH] 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. --- core/sqlite3_ondisk.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/sqlite3_ondisk.rs b/core/sqlite3_ondisk.rs index 9d1888354..1d5434e16 100644 --- a/core/sqlite3_ondisk.rs +++ b/core/sqlite3_ondisk.rs @@ -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)) } }