core: Optimize read_value() for strings

This commit is contained in:
Pekka Enberg
2024-01-24 17:56:09 +02:00
parent 490c3b2dda
commit 7c05149bcf
2 changed files with 6 additions and 4 deletions

View File

@@ -401,8 +401,7 @@ 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())?;
Ok((Value::Text(value), n))
Ok((Value::Text(buf[0..n].to_vec()), n))
}
}
}

View File

@@ -5,7 +5,7 @@ pub enum Value {
Null,
Integer(i64),
Float(f64),
Text(String),
Text(Vec<u8>),
Blob(Vec<u8>),
}
@@ -27,7 +27,10 @@ impl FromValue for i64 {
impl FromValue for String {
fn from_value(value: &Value) -> Result<Self> {
match value {
Value::Text(s) => Ok(s.clone()),
Value::Text(s) => {
let s = std::str::from_utf8(s)?;
Ok(s.to_string())
},
_ => anyhow::bail!("Expected text value"),
}
}