mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-24 18:34:34 +01:00
core: Optimize read_value() for strings
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user