Skip to content

Commit 0d54cf0

Browse files
authored
Stop zeroing buffers in the local file storage. (#4712)
1 parent b5611a2 commit 0d54cf0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

quickwit/quickwit-storage/src/file_descriptor_cache.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ impl SplitFile {
160160
use std::os::unix::fs::FileExt;
161161
let file = self.clone();
162162
let buf = tokio::task::spawn_blocking(move || {
163-
let mut buf = vec![0u8; range.len()];
163+
let mut buf = Vec::with_capacity(range.len());
164+
#[allow(clippy::uninit_vec)]
165+
unsafe {
166+
buf.set_len(range.len());
167+
}
164168
file.0.file.read_exact_at(&mut buf, range.start as u64)?;
165169
io::Result::Ok(buf)
166170
})

quickwit/quickwit-storage/src/local_file_storage.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,15 @@ impl Storage for LocalFileStorage {
215215
let full_path = self.full_path(path)?;
216216
tokio::task::spawn_blocking(move || {
217217
use std::io::{Read, Seek};
218-
219218
// we run these io in a spawn_blocking so there is no scheduling delay between each
220219
// step, as there would be if using tokio async File.
221220
let mut file = std::fs::File::open(full_path)?;
222221
file.seek(SeekFrom::Start(range.start as u64))?;
223-
let mut content_bytes: Vec<u8> = vec![0u8; range.len()];
222+
let mut content_bytes: Vec<u8> = Vec::with_capacity(range.len());
223+
#[allow(clippy::uninit_vec)]
224+
unsafe {
225+
content_bytes.set_len(range.len());
226+
}
224227
file.read_exact(&mut content_bytes)?;
225228
Ok(OwnedBytes::new(content_bytes))
226229
})

0 commit comments

Comments
 (0)