From 8f3a03426482e5cde2296badb9a48becc4732a2e Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 14 Sep 2024 13:26:34 -0700 Subject: [PATCH] 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. --- src/history.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/history.rs b/src/history.rs index 1d098cd52..c48e1d018 100644 --- a/src/history.rs +++ b/src/history.rs @@ -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, + old_item_offsets: Vec, } /// If set, we gave up on file locking because it took too long. @@ -463,7 +463,7 @@ fn populate_from_file_contents(&mut self) { 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 @@ fn new(name: WString) -> Self { last_identifier: 0, countdown_to_vacuum: None, loaded_old: false, - old_item_offsets: VecDeque::new(), + old_item_offsets: Vec::new(), } }