core: Switch to Rc in Value::Text

Makes deallocation much faster...
This commit is contained in:
Pekka Enberg
2024-01-27 10:09:35 +02:00
parent 0b3db02451
commit 3e6bf6892a
2 changed files with 5 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ use crate::pager::Page;
use crate::types::{Record, Value};
use crate::PageSource;
use anyhow::{anyhow, Result};
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use log::trace;
@@ -403,7 +404,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(Arc::new(value)), n))
Ok((Value::Text(Rc::new(value)), n))
}
}
}
@@ -468,7 +469,7 @@ mod tests {
#[case(&[], SerialType::ConstInt0, Value::Integer(0))]
#[case(&[], SerialType::ConstInt1, Value::Integer(1))]
#[case(&[1, 2, 3], SerialType::Blob(3), Value::Blob(vec![1, 2, 3]))]
#[case(&[65, 66, 67], SerialType::String(3), Value::Text("ABC".to_string()))]
#[case(&[65, 66, 67], SerialType::String(3), Value::Text("ABC".to_string().into()))]
fn test_read_value(
#[case] buf: &[u8],
#[case] serial_type: SerialType,

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::rc::Rc;
use anyhow::Result;
@@ -7,7 +7,7 @@ pub enum Value {
Null,
Integer(i64),
Float(f64),
Text(Arc<String>),
Text(Rc<String>),
Blob(Vec<u8>),
}