Skip to content

Commit af272e4

Browse files
authored
chore: remove redundant utility methods (#144)
#142 introduced some utility methods in the `Bound` struct. We had copies of these utility methods elsewhere, which are no longer needed and are removed in this commit.
1 parent 77d2a17 commit af272e4

File tree

3 files changed

+9
-32
lines changed

3 files changed

+9
-32
lines changed

src/btreemap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod allocator;
2828
mod iter;
2929
mod node;
3030
use crate::{
31-
storable::{max_size, Bound as StorableBound},
31+
storable::Bound as StorableBound,
3232
types::{Address, NULL},
3333
Memory, Storable,
3434
};
@@ -197,8 +197,8 @@ where
197197
/// This is only exposed for testing and benchmarking.
198198
#[cfg(any(feature = "profiler", test))]
199199
pub fn new_v1(memory: M) -> Self {
200-
let max_key_size = max_size::<K>();
201-
let max_value_size = max_size::<V>();
200+
let max_key_size = K::BOUND.max_size();
201+
let max_value_size = V::BOUND.max_size();
202202

203203
let btree = Self {
204204
root_addr: NULL,
@@ -235,12 +235,12 @@ where
235235
max_value_size: expected_value_size,
236236
}) => {
237237
assert!(
238-
max_size::<K>() <= expected_key_size,
238+
K::BOUND.max_size() <= expected_key_size,
239239
"max_key_size must be <= {expected_key_size}"
240240
);
241241

242242
assert!(
243-
max_size::<V>() <= expected_value_size,
243+
V::BOUND.max_size() <= expected_value_size,
244244
"max_value_size must be <= {expected_value_size}"
245245
);
246246
}

src/btreemap/node/v2.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@
7373
7474
use super::*;
7575
use crate::btreemap::Allocator;
76-
use crate::{
77-
btreemap::node::io::NodeWriter,
78-
storable::{is_fixed_size, max_size},
79-
types::NULL,
80-
};
76+
use crate::{btreemap::node::io::NodeWriter, types::NULL};
8177

8278
// Initial page
8379
pub(super) const OVERFLOW_ADDRESS_OFFSET: Bytes = Bytes::new(7);
@@ -159,9 +155,9 @@ impl<K: Storable + Ord + Clone> Node<K> {
159155
let mut buf = vec![];
160156
for _ in 0..num_entries {
161157
// Load the key's size.
162-
let key_size = if is_fixed_size::<K>() {
158+
let key_size = if K::BOUND.is_fixed_size() {
163159
// Key is fixed in size. The size of the key is always its max size.
164-
max_size::<K>()
160+
K::BOUND.max_size()
165161
} else {
166162
// Key is not fixed in size. Read the size from memory.
167163
let value = read_u32(&reader, offset);
@@ -251,7 +247,7 @@ impl<K: Storable + Ord + Clone> Node<K> {
251247
let key_bytes = key.to_bytes_checked();
252248

253249
// Write the size of the key if it isn't fixed in size.
254-
if !is_fixed_size::<K>() {
250+
if !K::BOUND.is_fixed_size() {
255251
writer.write_u32(offset, key_bytes.len() as u32);
256252
offset += U32_SIZE;
257253
}

src/storable.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -531,25 +531,6 @@ pub(crate) const fn bounds<A: Storable>() -> Bounds {
531531
}
532532
}
533533

534-
/// Returns the max size of the given type if bounded, panics if unbounded.
535-
pub const fn max_size<A: Storable>() -> u32 {
536-
if let Bound::Bounded { max_size, .. } = A::BOUND {
537-
max_size
538-
} else {
539-
panic!("Cannot get max size of unbounded type.");
540-
}
541-
}
542-
543-
/// Returns true if the type is fixed in size, false otherwise.
544-
pub const fn is_fixed_size<A: Storable>() -> bool {
545-
if let Bound::Bounded { is_fixed_size, .. } = A::BOUND {
546-
is_fixed_size
547-
} else {
548-
// Unbounded types do not have a fixed size.
549-
false
550-
}
551-
}
552-
553534
fn decode_size(src: &[u8], bounds: &Bounds) -> usize {
554535
if bounds.is_fixed_size {
555536
bounds.max_size as usize

0 commit comments

Comments
 (0)