From 8d74f4b8abf106d72cffc53dc78bb3273847f2d7 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Sun, 30 Mar 2025 11:07:23 +0200 Subject: [PATCH] remove unnecessary partial ord --- core/storage/sqlite3_ondisk.rs | 2 +- core/types.rs | 122 +-------------------------------- 2 files changed, 2 insertions(+), 122 deletions(-) diff --git a/core/storage/sqlite3_ondisk.rs b/core/storage/sqlite3_ondisk.rs index 05eed40f2..636b1acaf 100644 --- a/core/storage/sqlite3_ondisk.rs +++ b/core/storage/sqlite3_ondisk.rs @@ -1624,7 +1624,7 @@ mod tests { #[case] expected: OwnedValue, ) { let result = read_value(buf, serial_type).unwrap(); - assert_eq!(result.0, expected); + assert_eq!(result.0.to_owned(), expected); } #[test] diff --git a/core/types.rs b/core/types.rs index 90b6dcd27..a951f326c 100644 --- a/core/types.rs +++ b/core/types.rs @@ -747,7 +747,7 @@ impl ImmutableRecord { let value = value.get_owned_value(); let serial_type = SerialType::from(value); let n = write_varint(&mut serial_type_buf[0..], serial_type.into()); - serials.push((serial_type_buf.clone(), n)); + serials.push((serial_type_buf, n)); let value_size = match serial_type { SerialType::Null => 0, @@ -1007,126 +1007,6 @@ impl PartialOrd for RefValue { } } -#[allow(clippy::non_canonical_partial_ord_impl)] -impl PartialOrd for RefValue { - fn partial_cmp(&self, other: &OwnedValue) -> Option { - match (self, other) { - (Self::Integer(int_left), OwnedValue::Integer(int_right)) => { - int_left.partial_cmp(int_right) - } - (Self::Integer(int_left), OwnedValue::Float(float_right)) => { - (*int_left as f64).partial_cmp(float_right) - } - (Self::Float(float_left), OwnedValue::Integer(int_right)) => { - float_left.partial_cmp(&(*int_right as f64)) - } - (Self::Float(float_left), OwnedValue::Float(float_right)) => { - float_left.partial_cmp(float_right) - } - // Numeric vs Text/Blob - (Self::Integer(_) | Self::Float(_), OwnedValue::Text(_) | OwnedValue::Blob(_)) => { - Some(std::cmp::Ordering::Less) - } - (Self::Text(_) | Self::Blob(_), OwnedValue::Integer(_) | OwnedValue::Float(_)) => { - Some(std::cmp::Ordering::Greater) - } - - (Self::Text(text_left), OwnedValue::Text(text_right)) => { - let text_left = text_left.value.to_slice(); - text_left.partial_cmp(&text_right.value) - } - // Text vs Blob - (Self::Text(_), OwnedValue::Blob(_)) => Some(std::cmp::Ordering::Less), - (Self::Blob(_), OwnedValue::Text(_)) => Some(std::cmp::Ordering::Greater), - - (Self::Blob(blob_left), OwnedValue::Blob(blob_right)) => { - let blob_left = blob_left.to_slice(); - blob_left.partial_cmp(blob_right) - } - (Self::Null, OwnedValue::Null) => Some(std::cmp::Ordering::Equal), - (Self::Null, _) => Some(std::cmp::Ordering::Less), - (_, OwnedValue::Null) => Some(std::cmp::Ordering::Greater), - } - } -} - -#[allow(clippy::non_canonical_partial_ord_impl)] -impl PartialOrd for OwnedValue { - fn partial_cmp(&self, other: &RefValue) -> Option { - match (self, other) { - (Self::Integer(int_left), RefValue::Integer(int_right)) => { - int_left.partial_cmp(int_right) - } - (Self::Integer(int_left), RefValue::Float(float_right)) => { - (*int_left as f64).partial_cmp(float_right) - } - (Self::Float(float_left), RefValue::Integer(int_right)) => { - float_left.partial_cmp(&(*int_right as f64)) - } - (Self::Float(float_left), RefValue::Float(float_right)) => { - float_left.partial_cmp(float_right) - } - // Numeric vs Text/Blob - (Self::Integer(_) | Self::Float(_), RefValue::Text(_) | RefValue::Blob(_)) => { - Some(std::cmp::Ordering::Less) - } - (Self::Text(_) | Self::Blob(_), RefValue::Integer(_) | RefValue::Float(_)) => { - Some(std::cmp::Ordering::Greater) - } - - (Self::Text(text_left), RefValue::Text(text_right)) => { - let text_right = text_right.value.to_slice(); - text_left.value.as_slice().partial_cmp(text_right) - } - // Text vs Blob - (Self::Text(_), RefValue::Blob(_)) => Some(std::cmp::Ordering::Less), - (Self::Blob(_), RefValue::Text(_)) => Some(std::cmp::Ordering::Greater), - - (Self::Blob(blob_left), RefValue::Blob(blob_right)) => { - let blob_right = blob_right.to_slice(); - blob_left.as_slice().partial_cmp(blob_right) - } - (Self::Null, RefValue::Null) => Some(std::cmp::Ordering::Equal), - (Self::Null, _) => Some(std::cmp::Ordering::Less), - (_, RefValue::Null) => Some(std::cmp::Ordering::Greater), - } - } -} - -impl PartialEq for OwnedValue { - fn eq(&self, other: &RefValue) -> bool { - match (self, other) { - (Self::Integer(int_left), RefValue::Integer(int_right)) => int_left == int_right, - (Self::Float(float_left), RefValue::Float(float_right)) => float_left == float_right, - (Self::Text(text_left), RefValue::Text(text_right)) => { - text_left.value.as_slice() == text_right.value.to_slice() - } - (Self::Blob(blob_left), RefValue::Blob(blob_right)) => { - blob_left.as_slice() == blob_right.to_slice() - } - (Self::Null, RefValue::Null) => true, - _ => false, - } - } -} - -impl PartialEq for RefValue { - fn eq(&self, other: &OwnedValue) -> bool { - match (self, other) { - (Self::Integer(int_left), OwnedValue::Integer(int_right)) => int_left == int_right, - (Self::Float(float_left), OwnedValue::Float(float_right)) => float_left == float_right, - (Self::Text(text_left), OwnedValue::Text(text_right)) => { - text_left.value.to_slice() == text_right.value.as_slice() - } - (Self::Blob(blob_left), OwnedValue::Blob(blob_right)) => { - blob_left.to_slice() == blob_right.as_slice() - } - (Self::Null, OwnedValue::Null) => true, - _ => false, - } - } -} - pub fn compare_immutable(l: &[RefValue], r: &[RefValue]) -> std::cmp::Ordering { l.partial_cmp(r).unwrap() }