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).
#[inline]
pub fn is_plain(self) -> bool {
match self.0 {
LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. } => true,
_ => false,
}
matches!(self.0, LiteralRefContent::String(_) | LiteralRefContent::LanguageTaggedString { .. })
}
#[inline]

@ -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]

@ -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<()> {
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<TermRef<'a>>, 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())

@ -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) => {

@ -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);

@ -256,23 +256,19 @@ impl<I: StrId> Hash for EncodedTerm<I> {
impl<I: StrId> EncodedTerm<I> {
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<I: StrId> EncodedTerm<I> {
| 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<J: StrId>(self, mapping: impl Fn(I) -> J) -> EncodedTerm<J> {

Loading…
Cancel
Save