Oxrdf: Uses Box instead of Arc

We don't clone too often nested triples
pull/190/head
Tpt 3 years ago
parent bdf342b825
commit 621c134ed7
  1. 5
      js/src/model.rs
  2. 33
      lib/oxrdf/src/triple.rs

@ -5,7 +5,6 @@ use crate::utils::to_err;
use js_sys::{Reflect, UriError}; use js_sys::{Reflect, UriError};
use oxigraph::model::*; use oxigraph::model::*;
use oxigraph::sparql::Variable; use oxigraph::sparql::Variable;
use std::sync::Arc;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
thread_local! { thread_local! {
@ -515,8 +514,8 @@ impl From<Triple> for JsTerm {
} }
} }
impl From<Arc<Triple>> for JsTerm { impl From<Box<Triple>> for JsTerm {
fn from(triple: Arc<Triple>) -> Self { fn from(triple: Box<Triple>) -> Self {
triple.as_ref().clone().into() triple.as_ref().clone().into()
} }
} }

@ -3,7 +3,6 @@ use crate::literal::Literal;
use crate::named_node::NamedNode; use crate::named_node::NamedNode;
use crate::{BlankNodeRef, LiteralRef, NamedNodeRef}; use crate::{BlankNodeRef, LiteralRef, NamedNodeRef};
use std::fmt; use std::fmt;
use std::sync::Arc;
/// The owned union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node). /// The owned union of [IRIs](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) and [blank nodes](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node).
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
@ -158,7 +157,7 @@ pub enum Subject {
NamedNode(NamedNode), NamedNode(NamedNode),
BlankNode(BlankNode), BlankNode(BlankNode),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Triple(Arc<Triple>), Triple(Box<Triple>),
} }
impl Subject { impl Subject {
@ -228,15 +227,7 @@ impl From<BlankNodeRef<'_>> for Subject {
impl From<Triple> for Subject { impl From<Triple> for Subject {
#[inline] #[inline]
fn from(node: Triple) -> Self { fn from(node: Triple) -> Self {
Self::Triple(Arc::new(node)) Self::Triple(Box::new(node))
}
}
#[cfg(feature = "rdf-star")]
impl From<Arc<Triple>> for Subject {
#[inline]
fn from(node: Arc<Triple>) -> Self {
Self::Triple(node)
} }
} }
@ -244,7 +235,7 @@ impl From<Arc<Triple>> for Subject {
impl From<Box<Triple>> for Subject { impl From<Box<Triple>> for Subject {
#[inline] #[inline]
fn from(node: Box<Triple>) -> Self { fn from(node: Box<Triple>) -> Self {
Self::Triple(node.into()) Self::Triple(node)
} }
} }
@ -305,7 +296,7 @@ impl<'a> SubjectRef<'a> {
Self::NamedNode(node) => Subject::NamedNode(node.into_owned()), Self::NamedNode(node) => Subject::NamedNode(node.into_owned()),
Self::BlankNode(node) => Subject::BlankNode(node.into_owned()), Self::BlankNode(node) => Subject::BlankNode(node.into_owned()),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Triple(triple) => Subject::Triple(Arc::new(triple.clone())), Self::Triple(triple) => Subject::Triple(Box::new(triple.clone())),
} }
} }
} }
@ -397,7 +388,7 @@ pub enum Term {
BlankNode(BlankNode), BlankNode(BlankNode),
Literal(Literal), Literal(Literal),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Triple(Arc<Triple>), Triple(Box<Triple>),
} }
impl Term { impl Term {
@ -487,15 +478,7 @@ impl From<LiteralRef<'_>> for Term {
impl From<Triple> for Term { impl From<Triple> for Term {
#[inline] #[inline]
fn from(triple: Triple) -> Self { fn from(triple: Triple) -> Self {
Self::Triple(Arc::new(triple)) Self::Triple(Box::new(triple))
}
}
#[cfg(feature = "rdf-star")]
impl From<Arc<Triple>> for Term {
#[inline]
fn from(node: Arc<Triple>) -> Self {
Self::Triple(node)
} }
} }
@ -503,7 +486,7 @@ impl From<Arc<Triple>> for Term {
impl From<Box<Triple>> for Term { impl From<Box<Triple>> for Term {
#[inline] #[inline]
fn from(node: Box<Triple>) -> Self { fn from(node: Box<Triple>) -> Self {
Self::Triple(node.into()) Self::Triple(node)
} }
} }
@ -591,7 +574,7 @@ impl<'a> TermRef<'a> {
Self::BlankNode(node) => Term::BlankNode(node.into_owned()), Self::BlankNode(node) => Term::BlankNode(node.into_owned()),
Self::Literal(literal) => Term::Literal(literal.into_owned()), Self::Literal(literal) => Term::Literal(literal.into_owned()),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Triple(triple) => Term::Triple(Arc::new(triple.clone())), Self::Triple(triple) => Term::Triple(Box::new(triple.clone())),
} }
} }
} }

Loading…
Cancel
Save