-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
db-api: trait Compress and Encode use reference self #11186
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ pub struct RawKey<K: Key> { | |
impl<K: Key> RawKey<K> { | ||
/// Create new raw key. | ||
pub fn new(key: K) -> Self { | ||
Self { key: K::encode(key).into(), _phantom: std::marker::PhantomData } | ||
Self { key: K::encode(&key).into(), _phantom: std::marker::PhantomData } | ||
} | ||
|
||
/// Creates a raw key from an existing `Vec`. Useful when we already have the encoded | ||
|
@@ -89,8 +89,8 @@ impl AsRef<[u8]> for RawKey<Vec<u8>> { | |
impl<K: Key> Encode for RawKey<K> { | ||
type Encoded = Vec<u8>; | ||
|
||
fn encode(self) -> Self::Encoded { | ||
self.key | ||
fn encode(&self) -> Self::Encoded { | ||
self.key.clone() | ||
} | ||
} | ||
|
||
|
@@ -113,7 +113,7 @@ pub struct RawValue<V: Value> { | |
impl<V: Value> RawValue<V> { | ||
/// Create new raw value. | ||
pub fn new(value: V) -> Self { | ||
Self { value: V::compress(value).into(), _phantom: std::marker::PhantomData } | ||
Self { value: V::compress(&value).into(), _phantom: std::marker::PhantomData } | ||
} | ||
|
||
/// Creates a raw value from an existing `Vec`. Useful when we already have the encoded | ||
|
@@ -158,11 +158,11 @@ impl<V: Value> Compress for RawValue<V> { | |
Some(&self.value) | ||
} | ||
|
||
fn compress(self) -> Self::Compressed { | ||
self.value | ||
fn compress(&self) -> Self::Compressed { | ||
self.value.clone() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. headers, tx_lookup and hashing_account stages use this heavily, tbh don't know the impact of cloning for each row wdyt @DaniPopes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to return always better to call clone in context using return value, so the dev is conscious of this perf downgrade wherever it's used. |
||
} | ||
|
||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(self, buf: &mut B) { | ||
fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) { | ||
buf.put_slice(self.value.as_slice()) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same