History to store old item offsets in Vec and not VecDeque

We used deque in C++ because this vector may be large, and so it avoids
repeated re-allocations. But VecDeque is different in Rust - it's contiguous -
so there's no benefit. Just use Vec.
This commit is contained in:
Peter Ammon 2024-09-14 13:26:34 -07:00
parent 7ac62bbca4
commit 8f3a034264
No known key found for this signature in database

View file

@ -19,7 +19,7 @@
use crate::{common::cstr2wcstring, env::EnvVar, wcstringutil::trim};
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap, HashSet, VecDeque},
collections::{BTreeMap, HashMap, HashSet},
ffi::CString,
fs::File,
io::{BufRead, Read, Seek, SeekFrom, Write},
@ -379,7 +379,7 @@ struct HistoryImpl {
/// Whether we've loaded old items.
loaded_old: bool, // false
/// List of old items, as offsets into out mmap data.
old_item_offsets: VecDeque<usize>,
old_item_offsets: Vec<usize>,
}
/// If set, we gave up on file locking because it took too long.
@ -463,7 +463,7 @@ impl HistoryImpl {
file_contents.offset_of_next_item(&mut cursor, Some(self.boundary_timestamp))
{
// Remember this item.
self.old_item_offsets.push_back(offset);
self.old_item_offsets.push(offset);
}
}
@ -982,7 +982,7 @@ impl HistoryImpl {
last_identifier: 0,
countdown_to_vacuum: None,
loaded_old: false,
old_item_offsets: VecDeque::new(),
old_item_offsets: Vec::new(),
}
}