Skip to content

Commit 4bd7371

Browse files
fixup! Remove need for generic array and typenum constants
1 parent ef43c73 commit 4bd7371

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/driver.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ mod private {
1818

1919
/// Current capacity, set by the last call to [`set_capacity`](Buffer::set_capacity)
2020
/// or at initialization through [`with_capacity`](Buffer::with_capacity)
21-
fn current_capacity(&self) -> usize;
21+
fn current_len(&self) -> usize;
2222

2323
/// Can panic if `capacity` > `Self::MAX_CAPACITY`
24-
fn set_capacity(&mut self, capacity: usize);
25-
26-
/// Can panic if `capacity` > `Self::MAX_CAPACITY`
27-
fn with_capacity(capacity: usize) -> Self;
24+
fn with_len(capacity: usize) -> Self;
2825
}
2926
}
3027

@@ -44,14 +41,11 @@ impl<const N: usize> private::Sealed for [u8; N] {
4441
<[u8]>::as_mut_ptr(self)
4542
}
4643

47-
fn current_capacity(&self) -> usize {
44+
fn current_len(&self) -> usize {
4845
N
4946
}
5047

51-
fn set_capacity(&mut self, _capacity: usize) {
52-
// noop, fixed capacity
53-
}
54-
fn with_capacity(capacity: usize) -> Self {
48+
fn with_len(capacity: usize) -> Self {
5549
assert!(capacity <= N);
5650
[0; N]
5751
}
@@ -71,17 +65,13 @@ impl private::Sealed for alloc::vec::Vec<u8> {
7165
<[u8]>::as_mut_ptr(self)
7266
}
7367

74-
fn current_capacity(&self) -> usize {
75-
self.capacity()
76-
}
77-
78-
fn set_capacity(&mut self, capacity: usize) {
79-
self.resize(capacity, 0)
68+
fn current_len(&self) -> usize {
69+
self.len()
8070
}
8171

82-
fn with_capacity(capacity: usize) -> Self {
72+
fn with_len(capacity: usize) -> Self {
8373
let mut this = alloc::vec::Vec::with_capacity(capacity);
84-
this.set_capacity(capacity);
74+
this.resize(capacity, 0);
8575
this
8676
}
8777
}

src/fs.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ struct Cache<Storage: driver::Storage> {
4343
read: UnsafeCell<Storage::CACHE_BUFFER>,
4444
write: UnsafeCell<Storage::CACHE_BUFFER>,
4545
// lookahead: aligned::Aligned<aligned::A4, Bytes<Storage::LOOKAHEAD_SIZE>>,
46-
lookahead: UnsafeCell<Storage::CACHE_BUFFER>,
46+
lookahead: UnsafeCell<Storage::LOOKAHEAD_BUFFER>,
4747
size: usize,
4848
}
4949

5050
impl<S: driver::Storage> Cache<S> {
5151
pub fn new(storage: &S) -> Self {
5252
let cache_size = storage.cache_size();
53+
let lookahaed_size = storage.lookahead_size();
5354
Self {
54-
read: UnsafeCell::new(S::CACHE_BUFFER::with_capacity(cache_size)),
55-
write: UnsafeCell::new(S::CACHE_BUFFER::with_capacity(cache_size)),
56-
lookahead: UnsafeCell::new(S::CACHE_BUFFER::with_capacity(cache_size)),
55+
read: UnsafeCell::new(S::CACHE_BUFFER::with_len(cache_size)),
56+
write: UnsafeCell::new(S::CACHE_BUFFER::with_len(cache_size)),
57+
lookahead: UnsafeCell::new(S::LOOKAHEAD_BUFFER::with_len(lookahaed_size * 8)),
5758
size: cache_size,
5859
}
5960
}
@@ -537,7 +538,7 @@ impl<S: driver::Storage> FileAllocation<S> {
537538
pub fn new(cache_size: usize) -> Self {
538539
debug_assert!(cache_size > 0);
539540
Self {
540-
cache: UnsafeCell::new(S::CACHE_BUFFER::with_capacity(cache_size)),
541+
cache: UnsafeCell::new(S::CACHE_BUFFER::with_len(cache_size)),
541542
cache_size,
542543
state: unsafe { mem::MaybeUninit::zeroed().assume_init() },
543544
config: unsafe { mem::MaybeUninit::zeroed().assume_init() },

0 commit comments

Comments
 (0)