Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
wasm-forge committed Aug 31, 2024
1 parent 7574529 commit 0c55261
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ pub trait Storage {
fn rm_direntry(&mut self, node: Node, index: DirEntryIndex);

// read node data into buf
fn read(&mut self, node: Node, read_offset: FileSize, buf: &mut [u8]) -> Result<FileSize, Error>;
fn read(
&mut self,
node: Node,
read_offset: FileSize,
buf: &mut [u8],
) -> Result<FileSize, Error>;

// Write file at the current file cursor, the cursor position will NOT be updated after reading.
fn write(&mut self, node: Node, offset: FileSize, buf: &[u8]) -> Result<FileSize, Error>;
Expand Down
11 changes: 2 additions & 9 deletions src/storage/stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct StorageMemories<M: Memory> {
v2_allocator_memory: VirtualMemory<M>,
}



#[repr(C)]
pub struct StableStorage<M: Memory> {
header: Cell<Header, VirtualMemory<M>>,
Expand Down Expand Up @@ -254,7 +252,6 @@ impl<M: Memory> StableStorage<M> {
self.last_index = (node, index, chunk_ptr);

self.v2_chunks.write(chunk_ptr + offset, buf);

}

fn read_chunks_v1(
Expand Down Expand Up @@ -302,15 +299,13 @@ impl<M: Memory> StableStorage<M> {
Ok(size_read)
}


fn read_chunks_v2(
&mut self,
node: Node,
offset: FileSize,
file_size: FileSize,
buf: &mut [u8],
) -> Result<FileSize, Error> {

// compute remainder to read
let mut remainder = file_size - offset;

Expand All @@ -332,7 +327,7 @@ impl<M: Memory> StableStorage<M> {
let mut size_read: FileSize = 0;

if self.last_index.0 == node && self.last_index.1 == start_index {
//
//
let chunk_ptr = self.last_index.2;

let chunk_space = chunk_size as FileSize - chunk_offset;
Expand All @@ -350,8 +345,7 @@ impl<M: Memory> StableStorage<M> {
size_read += to_read;
remainder -= to_read;

range = (node, start_index+1)..(node, end_index);

range = (node, start_index + 1)..(node, end_index);
}

// early exit, if managed to completely read from the cached ptr
Expand Down Expand Up @@ -481,7 +475,6 @@ impl<M: Memory> Storage for StableStorage<M> {
memory.read(offset, &mut buf[..to_read as usize]);
to_read
} else {

let mut use_v2 = true;

if metadata.size > 0 {
Expand Down
2 changes: 1 addition & 1 deletion tests/canister_initial/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/canister_upgraded/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c55261

Please sign in to comment.