Use lasso for temporary strings during query evaluation

pull/46/head
Tpt 4 years ago
parent 5038d95a00
commit 0a6a09bcb4
  1. 1
      lib/Cargo.toml
  2. 18
      lib/src/sparql/dataset.rs

@ -35,6 +35,7 @@ hex = "0.4"
nom = "5" nom = "5"
peg = "0.6" peg = "0.6"
siphasher = "0.3" siphasher = "0.3"
lasso = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3" js-sys = "0.3"

@ -1,15 +1,15 @@
use crate::sparql::EvaluationError; use crate::sparql::EvaluationError;
use crate::store::numeric_encoder::{ use crate::store::numeric_encoder::{
EncodedQuad, EncodedTerm, MemoryStrStore, StrContainer, StrHash, StrId, StrLookup, EncodedQuad, EncodedTerm, StrContainer, StrId, StrLookup, WithStoreError,
WithStoreError,
}; };
use crate::store::ReadableEncodedStore; use crate::store::ReadableEncodedStore;
use lasso::{Rodeo, Spur};
use std::cell::RefCell; use std::cell::RefCell;
use std::iter::empty; use std::iter::empty;
pub(crate) struct DatasetView<S: ReadableEncodedStore> { pub(crate) struct DatasetView<S: ReadableEncodedStore> {
store: S, store: S,
extra: RefCell<MemoryStrStore>, extra: RefCell<Rodeo>,
default_graph_as_union: bool, default_graph_as_union: bool,
} }
@ -17,7 +17,7 @@ impl<S: ReadableEncodedStore> DatasetView<S> {
pub fn new(store: S, default_graph_as_union: bool) -> Self { pub fn new(store: S, default_graph_as_union: bool) -> Self {
Self { Self {
store, store,
extra: RefCell::new(MemoryStrStore::default()), extra: RefCell::new(Rodeo::default()),
default_graph_as_union, default_graph_as_union,
} }
} }
@ -32,12 +32,14 @@ impl<S: ReadableEncodedStore> StrLookup for DatasetView<S> {
fn get_str(&self, id: DatasetStrId<S::StrId>) -> Result<Option<String>, EvaluationError> { fn get_str(&self, id: DatasetStrId<S::StrId>) -> Result<Option<String>, EvaluationError> {
match id { match id {
DatasetStrId::Store(id) => self.store.get_str(id).map_err(|e| e.into()), 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<Option<DatasetStrId<S::StrId>>, EvaluationError> { fn get_str_id(&self, value: &str) -> Result<Option<DatasetStrId<S::StrId>>, 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))) Ok(Some(DatasetStrId::Temporary(id)))
} else { } else {
Ok(self Ok(self
@ -158,7 +160,7 @@ impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView<S> {
Ok(DatasetStrId::Store(id)) Ok(DatasetStrId::Store(id))
} else { } else {
Ok(DatasetStrId::Temporary( 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<S> {
#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)]
pub enum DatasetStrId<I: StrId> { pub enum DatasetStrId<I: StrId> {
Store(I), Store(I),
Temporary(StrHash), Temporary(Spur),
} }
impl<I: StrId> StrId for DatasetStrId<I> {} impl<I: StrId> StrId for DatasetStrId<I> {}

Loading…
Cancel
Save