refactor: make fill_default use Vec::resize_with (#53)

This commit is contained in:
Mikołaj Pieczaba
2025-02-23 22:35:29 +01:00
committed by GitHub
parent aae1f9d37b
commit 7e4bee516b
+3 -5
View File
@@ -46,12 +46,10 @@ struct PrevRender {
contained_term: Option<bool> contained_term: Option<bool>
} }
#[inline]
pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) { pub fn fill_default<T: Default>(vec: &mut Vec<T>, size: usize) {
vec.clear(); vec.clear();
vec.reserve(size.saturating_sub(vec.len())); vec.resize_with(size, T::default);
for _ in 0..size {
vec.push(T::default());
}
} }
// this function has to be sync (non-async) because the mupdf::Document needs to be held during // this function has to be sync (non-async) because the mupdf::Document needs to be held during
@@ -141,7 +139,7 @@ pub fn start_rendering(
// `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`), // `split_at_mut` at 0 initially (which bascially makes `right == rendered && left == []`),
// doing basically nothing, but if we get a notification that something has been jumped to, // doing basically nothing, but if we get a notification that something has been jumped to,
// then we can split at that page and render at both sides of it // then we can split at that page and render at both sides of it
let mut rendered = vec![]; let mut rendered = Vec::new();
fill_default::<PrevRender>(&mut rendered, n_pages); fill_default::<PrevRender>(&mut rendered, n_pages);
let mut start_point = 0; let mut start_point = 0;