From 12fb800492a23f0cb4b39cdcca92ce7d98024b94 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 8 Apr 2024 15:47:25 +0800 Subject: [PATCH 1/4] flush if over sized --- src/fs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fs.rs b/src/fs.rs index f886cf5..33913a9 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -407,6 +407,9 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { }; self.len += size; + if self.len >= SIZE { + self.flush()?; + } Ok(node_id) } } From 1f8d5a0cfe0525b73cd50f4c1f34eb1a4d074eae Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 8 Apr 2024 16:00:43 +0800 Subject: [PATCH 2/4] reduce scope of config --- src/fs.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 33913a9..5b5d746 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -382,8 +382,6 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { self.flush()?; } - let config = config::standard(); - if node.inner.is_none() { if node.id != EMPTY_RECORD { return Ok(node.id); @@ -393,6 +391,7 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { let size = { let inner = node.inner.as_mut().unwrap(); + let config = config::standard(); bincode::encode_into_slice(inner, &mut self.tail(), config).map_err(|e| { io::Error::new( io::ErrorKind::Other, From 219b9a5f98f2c267756a4afd219a7c1e3c9b6c3b Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 8 Apr 2024 17:57:46 +0800 Subject: [PATCH 3/4] Node doesn't have to be mut --- src/fs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 5b5d746..8835256 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -377,7 +377,7 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { Ok(record) } - pub fn write_node(&mut self, node: &mut Node) -> Result { + pub fn write_node(&mut self, node: &Node) -> Result { if self.remaining() < node.mem_size() { self.flush()?; } @@ -390,7 +390,7 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { } let size = { - let inner = node.inner.as_mut().unwrap(); + let inner = node.inner.as_ref().unwrap(); let config = config::standard(); bincode::encode_into_slice(inner, &mut self.tail(), config).map_err(|e| { io::Error::new( From 4dffa6f0d1820991f8766baf6e9311de3c174caa Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Tue, 9 Apr 2024 15:23:29 +0800 Subject: [PATCH 4/4] remove impossible path --- src/fs.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 8835256..70d9d4e 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -406,9 +406,6 @@ impl<'file, const SIZE: usize> WriteBuffer<'file, SIZE> { }; self.len += size; - if self.len >= SIZE { - self.flush()?; - } Ok(node_id) } }