From 231da02e87216b3e860fcc38467a4024ff4aed14 Mon Sep 17 00:00:00 2001 From: Tpt Date: Mon, 12 Oct 2020 15:11:13 +0200 Subject: [PATCH] Uses matches! where relevant --- lib/src/model/literal.rs | 5 +---- lib/src/model/triple.rs | 30 ++++++------------------------ lib/src/sparql/csv_results.rs | 10 ++-------- lib/src/sparql/eval.rs | 6 ++---- lib/src/store/memory.rs | 2 +- lib/src/store/numeric_encoder.rs | 25 ++++++++----------------- 6 files changed, 20 insertions(+), 58 deletions(-) diff --git a/lib/src/model/literal.rs b/lib/src/model/literal.rs index e2ded4aa..52be875c 100644 --- a/lib/src/model/literal.rs +++ b/lib/src/model/literal.rs @@ -508,10 +508,7 @@ impl<'a> LiteralRef<'a> { /// or has the datatype [xsd:string](http://www.w3.org/2001/XMLSchema#string). #[inline] pub fn is_plain(self) -> bool { - match self.0 { - LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } => true, - _ => false, - } + matches!(self.0, LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. }) } #[inline] diff --git a/lib/src/model/triple.rs b/lib/src/model/triple.rs index fb5fbd65..9c5272fb 100644 --- a/lib/src/model/triple.rs +++ b/lib/src/model/triple.rs @@ -275,26 +275,17 @@ pub enum TermRef<'a> { impl<'a> TermRef<'a> { #[inline] pub fn is_named_node(&self) -> bool { - match self { - Self::NamedNode(_) => true, - _ => false, - } + matches!(self, Self::NamedNode(_)) } #[inline] pub fn is_blank_node(&self) -> bool { - match self { - Self::BlankNode(_) => true, - _ => false, - } + matches!(self, Self::BlankNode(_)) } #[inline] pub fn is_literal(&self) -> bool { - match self { - Self::Literal(_) => true, - _ => false, - } + matches!(self, Self::Literal(_)) } #[inline] @@ -660,26 +651,17 @@ pub enum GraphNameRef<'a> { impl<'a> GraphNameRef<'a> { #[inline] pub fn is_named_node(&self) -> bool { - match self { - GraphNameRef::NamedNode(_) => true, - _ => false, - } + matches!(self, Self::NamedNode(_)) } #[inline] pub fn is_blank_node(&self) -> bool { - match self { - GraphNameRef::BlankNode(_) => true, - _ => false, - } + matches!(self, Self::BlankNode(_)) } #[inline] pub fn is_default_graph(&self) -> bool { - match self { - GraphNameRef::DefaultGraph => true, - _ => false, - } + matches!(self, Self::DefaultGraph) } #[inline] diff --git a/lib/src/sparql/csv_results.rs b/lib/src/sparql/csv_results.rs index 521c32e8..5c10b3a6 100644 --- a/lib/src/sparql/csv_results.rs +++ b/lib/src/sparql/csv_results.rs @@ -71,10 +71,7 @@ fn write_csv_term<'a>(term: impl Into>, mut sink: impl Write) -> io: } fn write_escaped_csv_string(s: &str, mut sink: impl Write) -> io::Result<()> { - if s.bytes().any(|c| match c { - b'"' | b',' | b'\n' | b'\r' => true, - _ => false, - }) { + if s.bytes().any(|c| matches!(c, b'"' | b',' | b'\n' | b'\r')) { sink.write_all(b"\"")?; for c in s.bytes() { if c == b'\"' { @@ -153,10 +150,7 @@ fn write_tsv_term<'a>(term: impl Into>, mut sink: impl Write) -> io: _ => sink.write_all(literal.to_string().as_bytes()), }, xsd::INTEGER => { - if literal.value().bytes().all(|c| match c { - b'0'..=b'9' => true, - _ => false, - }) { + if literal.value().bytes().all(|c| matches!(c, b'0'..=b'9')) { sink.write_all(literal.value().as_bytes()) } else { sink.write_all(literal.to_string().as_bytes()) diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 4fea9b78..b34bb747 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -1414,13 +1414,11 @@ where Some(self.eval_expression(e, tuple)?.is_literal().into()) } PlanExpression::IsNumeric(e) => Some( - match self.eval_expression(e, tuple)? { + matches!(self.eval_expression(e, tuple)?, EncodedTerm::FloatLiteral(_) | EncodedTerm::DoubleLiteral(_) | EncodedTerm::IntegerLiteral(_) - | EncodedTerm::DecimalLiteral(_) => true, - _ => false, - } + | EncodedTerm::DecimalLiteral(_)) .into(), ), PlanExpression::Regex(text, pattern, flags) => { diff --git a/lib/src/store/memory.rs b/lib/src/store/memory.rs index 1a178ecb..1c76d62f 100644 --- a/lib/src/store/memory.rs +++ b/lib/src/store/memory.rs @@ -1407,7 +1407,7 @@ fn hash_bnodes( 2, )); } - to_hash.sort(); + to_hash.sort_unstable(); let hash = hash_tuple((old_hash, &to_hash)); to_hash.clear(); new_hashes.insert(*bnode, hash); diff --git a/lib/src/store/numeric_encoder.rs b/lib/src/store/numeric_encoder.rs index dbc4340b..8487c8c7 100644 --- a/lib/src/store/numeric_encoder.rs +++ b/lib/src/store/numeric_encoder.rs @@ -256,23 +256,19 @@ impl Hash for EncodedTerm { impl EncodedTerm { pub fn is_named_node(&self) -> bool { - match self { - Self::NamedNode { .. } => true, - _ => false, - } + matches!(self, + Self::NamedNode { .. }) } pub fn is_blank_node(&self) -> bool { - match self { + matches!(self, Self::NumericalBlankNode { .. } | Self::SmallBlankNode { .. } - | Self::BigBlankNode { .. } => true, - _ => false, - } + | Self::BigBlankNode { .. }) } pub fn is_literal(&self) -> bool { - match self { + matches!(self, Self::SmallStringLiteral { .. } | Self::BigStringLiteral { .. } | Self::SmallSmallLangStringLiteral { .. } @@ -296,20 +292,15 @@ impl EncodedTerm { | Self::GMonthLiteral(_) | Self::DurationLiteral(_) | Self::YearMonthDurationLiteral(_) - | Self::DayTimeDurationLiteral(_) => true, - _ => false, - } + | Self::DayTimeDurationLiteral(_)) } pub fn is_unknown_typed_literal(&self) -> bool { - match self { - Self::SmallTypedLiteral { .. } | Self::BigTypedLiteral { .. } => true, - _ => false, - } + matches!(self, Self::SmallTypedLiteral { .. } | Self::BigTypedLiteral { .. }) } pub fn is_default_graph(&self) -> bool { - *self == EncodedTerm::DefaultGraph + matches!(self, Self::DefaultGraph) } pub fn map_id(self, mapping: impl Fn(I) -> J) -> EncodedTerm {