Avoids copies when returning SERVICE results

Makes sure that we do not lock too much the encoding dictionary to avoid "already locked" errors
pull/12/head
Tpt 5 years ago
parent 0d8ccdae3e
commit d026d3fc3e
  1. 25
      lib/src/sparql/eval.rs

@ -479,13 +479,13 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
} }
} }
fn evaluate_service( fn evaluate_service<'b>(
&self, &'b self,
service_name: &PatternValue, service_name: &PatternValue,
graph_pattern: &GraphPattern, graph_pattern: &GraphPattern,
variables: &[Variable], variables: &'b [Variable],
from: EncodedTuple, from: EncodedTuple,
) -> Result<EncodedTuplesIterator> { ) -> Result<EncodedTuplesIterator<'b>> {
let service_name = let service_name =
self.dataset self.dataset
.decode_named_node(get_pattern_value(service_name, &[]).ok_or_else(|| { .decode_named_node(get_pattern_value(service_name, &[]).ok_or_else(|| {
@ -497,13 +497,14 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
service_name service_name
) )
})?; })?;
let encoded = self.encode_bindings(variables, service(graph_pattern.clone())?); Ok(Box::new(
let collected = encoded.collect::<Vec<_>>(); self.encode_bindings(variables, service(graph_pattern.clone())?)
Ok(Box::new(JoinIterator { .flat_map(move |binding| {
left: vec![from], binding
right_iter: Box::new(collected.into_iter()), .map(|binding| combine_tuples(&binding, &from))
buffered_results: vec![], .transpose()
})) }),
))
} }
fn accumulator_for_aggregate<'b>( fn accumulator_for_aggregate<'b>(
@ -1618,7 +1619,6 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
where where
'a: 'b, 'a: 'b,
{ {
let mut encoder = self.dataset.encoder();
let (binding_variables, iter) = BindingsIterator::destruct(iter); let (binding_variables, iter) = BindingsIterator::destruct(iter);
let mut combined_variables = variables.to_vec(); let mut combined_variables = variables.to_vec();
for v in binding_variables.clone() { for v in binding_variables.clone() {
@ -1627,6 +1627,7 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
} }
} }
Box::new(iter.map(move |terms| { Box::new(iter.map(move |terms| {
let mut encoder = self.dataset.encoder();
let mut encoded_terms = vec![None; combined_variables.len()]; let mut encoded_terms = vec![None; combined_variables.len()];
for (i, term_option) in terms?.into_iter().enumerate() { for (i, term_option) in terms?.into_iter().enumerate() {
match term_option { match term_option {

Loading…
Cancel
Save