diff --git a/lib/Cargo.toml b/lib/Cargo.toml index fdf39fc3..795b7a49 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -35,6 +35,7 @@ hex = "0.4" nom = "5" peg = "0.6" siphasher = "0.3" +lasso = "0.3" [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = "0.3" diff --git a/lib/src/sparql/dataset.rs b/lib/src/sparql/dataset.rs index abaa7936..851a94c9 100644 --- a/lib/src/sparql/dataset.rs +++ b/lib/src/sparql/dataset.rs @@ -1,15 +1,15 @@ use crate::sparql::EvaluationError; use crate::store::numeric_encoder::{ - EncodedQuad, EncodedTerm, MemoryStrStore, StrContainer, StrHash, StrId, StrLookup, - WithStoreError, + EncodedQuad, EncodedTerm, StrContainer, StrId, StrLookup, WithStoreError, }; use crate::store::ReadableEncodedStore; +use lasso::{Rodeo, Spur}; use std::cell::RefCell; use std::iter::empty; pub(crate) struct DatasetView { store: S, - extra: RefCell, + extra: RefCell, default_graph_as_union: bool, } @@ -17,7 +17,7 @@ impl DatasetView { pub fn new(store: S, default_graph_as_union: bool) -> Self { Self { store, - extra: RefCell::new(MemoryStrStore::default()), + extra: RefCell::new(Rodeo::default()), default_graph_as_union, } } @@ -32,12 +32,14 @@ impl StrLookup for DatasetView { fn get_str(&self, id: DatasetStrId) -> Result, EvaluationError> { match id { DatasetStrId::Store(id) => self.store.get_str(id).map_err(|e| e.into()), - DatasetStrId::Temporary(id) => Ok(self.extra.borrow().get_str(id)?), + DatasetStrId::Temporary(id) => { + Ok(self.extra.borrow().try_resolve(&id).map(|e| e.to_owned())) + } } } fn get_str_id(&self, value: &str) -> Result>, EvaluationError> { - if let Some(id) = self.extra.borrow().get_str_id(value)? { + if let Some(id) = self.extra.borrow().get(value) { Ok(Some(DatasetStrId::Temporary(id))) } else { Ok(self @@ -158,7 +160,7 @@ impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView { Ok(DatasetStrId::Store(id)) } else { Ok(DatasetStrId::Temporary( - self.extra.borrow_mut().insert_str(value)?, + self.extra.borrow_mut().get_or_intern(value), )) } } @@ -167,7 +169,7 @@ impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView { #[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] pub enum DatasetStrId { Store(I), - Temporary(StrHash), + Temporary(Spur), } impl StrId for DatasetStrId {}