Uses matches! where relevant

pull/67/head
Tpt 4 years ago
parent a6121de361
commit 231da02e87
  1. 5
      lib/src/model/literal.rs
  2. 30
      lib/src/model/triple.rs
  3. 10
      lib/src/sparql/csv_results.rs
  4. 6
      lib/src/sparql/eval.rs
  5. 2
      lib/src/store/memory.rs
  6. 25
      lib/src/store/numeric_encoder.rs

@ -508,10 +508,7 @@ impl<'a> LiteralRef<'a> {
/// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string). /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string).
#[inline] #[inline]
pub fn is_plain(self) -> bool { pub fn is_plain(self) -> bool {
match self.0 { matches!(self.0, LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. })
LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } => true,
_ => false,
}
} }
#[inline] #[inline]

@ -275,26 +275,17 @@ pub enum TermRef<'a> {
impl<'a> TermRef<'a> { impl<'a> TermRef<'a> {
#[inline] #[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { matches!(self, Self::NamedNode(_))
Self::NamedNode(_) => true,
_ => false,
}
} }
#[inline] #[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { matches!(self, Self::BlankNode(_))
Self::BlankNode(_) => true,
_ => false,
}
} }
#[inline] #[inline]
pub fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
match self { matches!(self, Self::Literal(_))
Self::Literal(_) => true,
_ => false,
}
} }
#[inline] #[inline]
@ -660,26 +651,17 @@ pub enum GraphNameRef<'a> {
impl<'a> GraphNameRef<'a> { impl<'a> GraphNameRef<'a> {
#[inline] #[inline]
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { matches!(self, Self::NamedNode(_))
GraphNameRef::NamedNode(_) => true,
_ => false,
}
} }
#[inline] #[inline]
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { matches!(self, Self::BlankNode(_))
GraphNameRef::BlankNode(_) => true,
_ => false,
}
} }
#[inline] #[inline]
pub fn is_default_graph(&self) -> bool { pub fn is_default_graph(&self) -> bool {
match self { matches!(self, Self::DefaultGraph)
GraphNameRef::DefaultGraph => true,
_ => false,
}
} }
#[inline] #[inline]

@ -71,10 +71,7 @@ fn write_csv_term<'a>(term: impl Into<TermRef<'a>>, mut sink: impl Write) -> io:
} }
fn write_escaped_csv_string(s: &str, mut sink: impl Write) -> io::Result<()> { fn write_escaped_csv_string(s: &str, mut sink: impl Write) -> io::Result<()> {
if s.bytes().any(|c| match c { if s.bytes().any(|c| matches!(c, b'"' | b',' | b'\n' | b'\r')) {
b'"' | b',' | b'\n' | b'\r' => true,
_ => false,
}) {
sink.write_all(b"\"")?; sink.write_all(b"\"")?;
for c in s.bytes() { for c in s.bytes() {
if c == b'\"' { if c == b'\"' {
@ -153,10 +150,7 @@ fn write_tsv_term<'a>(term: impl Into<TermRef<'a>>, mut sink: impl Write) -> io:
_ => sink.write_all(literal.to_string().as_bytes()), _ => sink.write_all(literal.to_string().as_bytes()),
}, },
xsd::INTEGER => { xsd::INTEGER => {
if literal.value().bytes().all(|c| match c { if literal.value().bytes().all(|c| matches!(c, b'0'..=b'9')) {
b'0'..=b'9' => true,
_ => false,
}) {
sink.write_all(literal.value().as_bytes()) sink.write_all(literal.value().as_bytes())
} else { } else {
sink.write_all(literal.to_string().as_bytes()) sink.write_all(literal.to_string().as_bytes())

@ -1414,13 +1414,11 @@ where
Some(self.eval_expression(e, tuple)?.is_literal().into()) Some(self.eval_expression(e, tuple)?.is_literal().into())
} }
PlanExpression::IsNumeric(e) => Some( PlanExpression::IsNumeric(e) => Some(
match self.eval_expression(e, tuple)? { matches!(self.eval_expression(e, tuple)?,
EncodedTerm::FloatLiteral(_) EncodedTerm::FloatLiteral(_)
| EncodedTerm::DoubleLiteral(_) | EncodedTerm::DoubleLiteral(_)
| EncodedTerm::IntegerLiteral(_) | EncodedTerm::IntegerLiteral(_)
| EncodedTerm::DecimalLiteral(_) => true, | EncodedTerm::DecimalLiteral(_))
_ => false,
}
.into(), .into(),
), ),
PlanExpression::Regex(text, pattern, flags) => { PlanExpression::Regex(text, pattern, flags) => {

@ -1407,7 +1407,7 @@ fn hash_bnodes(
2, 2,
)); ));
} }
to_hash.sort(); to_hash.sort_unstable();
let hash = hash_tuple((old_hash, &to_hash)); let hash = hash_tuple((old_hash, &to_hash));
to_hash.clear(); to_hash.clear();
new_hashes.insert(*bnode, hash); new_hashes.insert(*bnode, hash);

@ -256,23 +256,19 @@ impl<I: StrId> Hash for EncodedTerm<I> {
impl<I: StrId> EncodedTerm<I> { impl<I: StrId> EncodedTerm<I> {
pub fn is_named_node(&self) -> bool { pub fn is_named_node(&self) -> bool {
match self { matches!(self,
Self::NamedNode { .. } => true, Self::NamedNode { .. })
_ => false,
}
} }
pub fn is_blank_node(&self) -> bool { pub fn is_blank_node(&self) -> bool {
match self { matches!(self,
Self::NumericalBlankNode { .. } Self::NumericalBlankNode { .. }
| Self::SmallBlankNode { .. } | Self::SmallBlankNode { .. }
| Self::BigBlankNode { .. } => true, | Self::BigBlankNode { .. })
_ => false,
}
} }
pub fn is_literal(&self) -> bool { pub fn is_literal(&self) -> bool {
match self { matches!(self,
Self::SmallStringLiteral { .. } Self::SmallStringLiteral { .. }
| Self::BigStringLiteral { .. } | Self::BigStringLiteral { .. }
| Self::SmallSmallLangStringLiteral { .. } | Self::SmallSmallLangStringLiteral { .. }
@ -296,20 +292,15 @@ impl<I: StrId> EncodedTerm<I> {
| Self::GMonthLiteral(_) | Self::GMonthLiteral(_)
| Self::DurationLiteral(_) | Self::DurationLiteral(_)
| Self::YearMonthDurationLiteral(_) | Self::YearMonthDurationLiteral(_)
| Self::DayTimeDurationLiteral(_) => true, | Self::DayTimeDurationLiteral(_))
_ => false,
}
} }
pub fn is_unknown_typed_literal(&self) -> bool { pub fn is_unknown_typed_literal(&self) -> bool {
match self { matches!(self, Self::SmallTypedLiteral { .. } | Self::BigTypedLiteral { .. })
Self::SmallTypedLiteral { .. } | Self::BigTypedLiteral { .. } => true,
_ => false,
}
} }
pub fn is_default_graph(&self) -> bool { pub fn is_default_graph(&self) -> bool {
*self == EncodedTerm::DefaultGraph matches!(self, Self::DefaultGraph)
} }
pub fn map_id<J: StrId>(self, mapping: impl Fn(I) -> J) -> EncodedTerm<J> { pub fn map_id<J: StrId>(self, mapping: impl Fn(I) -> J) -> EncodedTerm<J> {

Loading…
Cancel
Save