aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-05-09 12:38:55 +0200
committerAlex Auvolat <alex@adnab.me>2023-06-09 16:23:37 +0200
commit53bf2f070cd3ef95bbdf78e439dbeb2d8cda8f19 (patch)
tree318f72a46d10f1560a03c3759032a6d58b4340ec
parent412ab77b0815f165539fe41713c0155a9878672f (diff)
downloadgarage-53bf2f070cd3ef95bbdf78e439dbeb2d8cda8f19.tar.gz
garage-53bf2f070cd3ef95bbdf78e439dbeb2d8cda8f19.zip
undo sort_key() returning Cow
-rw-r--r--src/table/data.rs2
-rw-r--r--src/table/schema.rs18
-rw-r--r--src/table/util.rs6
3 files changed, 8 insertions, 18 deletions
diff --git a/src/table/data.rs b/src/table/data.rs
index cfc67c18..73fa93c8 100644
--- a/src/table/data.rs
+++ b/src/table/data.rs
@@ -347,7 +347,7 @@ impl<F: TableSchema, R: TableReplication> TableData<F, R> {
// ---- Utility functions ----
pub fn tree_key(&self, p: &F::P, s: &F::S) -> Vec<u8> {
- [p.hash().as_slice(), s.sort_key().as_ref()].concat()
+ [p.hash().as_slice(), s.sort_key()].concat()
}
pub fn decode_entry(&self, bytes: &[u8]) -> Result<F::E, Error> {
diff --git a/src/table/schema.rs b/src/table/schema.rs
index 7daf3000..fc1a465e 100644
--- a/src/table/schema.rs
+++ b/src/table/schema.rs
@@ -1,5 +1,3 @@
-use std::borrow::Cow;
-
use serde::{Deserialize, Serialize};
use garage_db as db;
@@ -38,24 +36,18 @@ impl PartitionKey for FixedBytes32 {
/// Trait for field used to sort data
pub trait SortKey: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static {
/// Get the key used to sort
- fn sort_key(&self) -> Cow<'_, [u8]>;
+ fn sort_key(&self) -> &[u8];
}
impl SortKey for String {
- fn sort_key(&self) -> Cow<'_, [u8]> {
- Cow::from(self.as_bytes())
+ fn sort_key(&self) -> &[u8] {
+ self.as_bytes()
}
}
impl SortKey for FixedBytes32 {
- fn sort_key(&self) -> Cow<'_, [u8]> {
- Cow::from(self.as_slice())
- }
-}
-
-impl SortKey for u32 {
- fn sort_key(&self) -> Cow<'_, [u8]> {
- Cow::from(u32::to_be_bytes(*self).to_vec())
+ fn sort_key(&self) -> &[u8] {
+ self.as_slice()
}
}
diff --git a/src/table/util.rs b/src/table/util.rs
index 39412c79..0b10cf3f 100644
--- a/src/table/util.rs
+++ b/src/table/util.rs
@@ -1,5 +1,3 @@
-use std::borrow::Cow;
-
use serde::{Deserialize, Serialize};
use garage_util::data::*;
@@ -9,8 +7,8 @@ use crate::schema::*;
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EmptyKey;
impl SortKey for EmptyKey {
- fn sort_key(&self) -> Cow<'_, [u8]> {
- Cow::from(&[][..])
+ fn sort_key(&self) -> &[u8] {
+ &[]
}
}
impl PartitionKey for EmptyKey {