Remove Box from Vec conversion

This commit is contained in:
Wildan M
2026-06-23 14:09:19 +07:00
parent 6767faba13
commit 47c9d242f5
3 changed files with 9 additions and 15 deletions
+3 -4
View File
@@ -1,6 +1,5 @@
use aes::Aes128;
use alloc::{
boxed::Box,
collections::{BTreeMap, VecDeque},
vec,
};
@@ -14,8 +13,8 @@ use crate::{
HEADER_RING, RECORD_SIZE,
};
fn compress_cache() -> Box<[u8]> {
vec![0; lz4_flex::block::get_maximum_output_size(RECORD_SIZE as usize)].into_boxed_slice()
fn compress_cache() -> Vec<u8> {
vec![0; lz4_flex::block::get_maximum_output_size(RECORD_SIZE as usize)]
}
/// A file system
@@ -28,7 +27,7 @@ pub struct FileSystem<D: Disk> {
pub header: Header,
pub(crate) allocator: Allocator,
pub(crate) cipher_opt: Option<Xts128<Aes128>>,
pub(crate) compress_cache: Box<[u8]>,
pub(crate) compress_cache: Vec<u8>,
pub node_usages: BTreeMap<u32, u64>,
}
+3 -4
View File
@@ -1,16 +1,15 @@
use alloc::{boxed::Box, vec};
use alloc::vec;
use core::ops;
use crate::{BlockLevel, BlockTrait, RECORD_LEVEL};
//TODO: this is a box to prevent stack overflows
#[derive(Clone)]
pub struct RecordRaw(pub(crate) Box<[u8]>);
pub struct RecordRaw(pub(crate) Vec<u8>);
unsafe impl BlockTrait for RecordRaw {
fn empty(level: BlockLevel) -> Option<Self> {
if level.0 <= RECORD_LEVEL {
Some(Self(vec![0; level.bytes() as usize].into_boxed_slice()))
Some(Self(vec![0; level.bytes() as usize]))
} else {
None
}
+3 -7
View File
@@ -1,5 +1,4 @@
use alloc::{
boxed::Box,
collections::{BTreeMap, VecDeque},
vec::Vec,
};
@@ -73,7 +72,7 @@ pub struct Transaction<'a, D: Disk> {
pub(crate) allocator: Allocator,
allocator_log: VecDeque<AllocEntry>,
deallocate: Vec<BlockAddr>,
pub(crate) write_cache: BTreeMap<BlockAddr, Box<[u8]>>,
pub(crate) write_cache: BTreeMap<BlockAddr, Vec<u8>>,
}
impl<'a, D: Disk> Transaction<'a, D> {
@@ -484,11 +483,8 @@ impl<'a, D: Disk> Transaction<'a, D> {
return Err(Error::new(ENOENT));
}
//TODO: do not convert to boxed slice if it already is one
self.write_cache.insert(
block.addr(),
block.data().deref().to_vec().into_boxed_slice(),
);
self.write_cache
.insert(block.addr(), block.data().deref().to_vec());
Ok(block.create_ptr())
}