mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
core: Make Value::Text reference counted
Avoids lots of memory copies as values get passed through the different layers.
This commit is contained in:
@@ -403,7 +403,7 @@ pub fn read_value(buf: &[u8], serial_type: &SerialType) -> Result<(Value, usize)
|
||||
}
|
||||
let bytes = buf[0..n].to_vec();
|
||||
let value = unsafe { String::from_utf8_unchecked(bytes) };
|
||||
Ok((Value::Text(value), n))
|
||||
Ok((Value::Text(Arc::new(value)), n))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -5,7 +7,7 @@ pub enum Value {
|
||||
Null,
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
Text(String),
|
||||
Text(Arc<String>),
|
||||
Blob(Vec<u8>),
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ 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) => Ok(s.to_string()),
|
||||
_ => anyhow::bail!("Expected text value"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user