diff --git a/Cargo.toml b/Cargo.toml index de5ed33f..f41316a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ cranelift-jit = "0.93" fast-float = "0.2" bumpalo = { version = "3.19.0", features = ["collections"] } target-lexicon = "0.12.2" +ordermap = "0.5.10" [dev-dependencies] assert_cmd = "2.0.3" diff --git a/src/interp.rs b/src/interp.rs index 20166132..bda2f810 100644 --- a/src/interp.rs +++ b/src/interp.rs @@ -7,7 +7,7 @@ use crate::runtime::{self, Float, Int, Line, LineReader, Str, UniqueStr}; use crossbeam::scope; use crossbeam_channel::bounded; -use hashbrown::HashMap; +use ordermap::map::OrderMap; use rand::{self, rngs::StdRng, Rng, SeedableRng}; use regex::bytes::Regex; @@ -51,12 +51,12 @@ pub(crate) struct Slots { pub int: Vec, pub float: Vec, pub strs: Vec>, - pub intint: Vec>, - pub intfloat: Vec>, - pub intstr: Vec>>, - pub strint: Vec, Int>>, - pub strfloat: Vec, Float>>, - pub strstr: Vec, UniqueStr<'static>>>, + pub intint: Vec>, + pub intfloat: Vec>, + pub intstr: Vec>>, + pub strint: Vec, Int>>, + pub strfloat: Vec, Float>>, + pub strstr: Vec, UniqueStr<'static>>>, } /// A Simple helper trait for implement aggregations for slot values and variables. @@ -83,8 +83,8 @@ impl<'a> Agg for UniqueStr<'a> { } } } -impl Agg for HashMap { - fn agg(mut self, other: HashMap) -> HashMap { +impl Agg for OrderMap { + fn agg(mut self, other: OrderMap) -> OrderMap { for (k, v) in other { let entry = self.entry(k).or_default(); let v2 = mem::take(entry); diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 5c453e11..3e285fe1 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -1,6 +1,7 @@ use crate::common::{FileSpec, Result}; use grep_cli::CommandReader; use hashbrown::HashMap; +use ordermap::map::{OrderMap, RawEntryApiV1}; use regex::bytes::Regex; use std::cell::{Cell, RefCell}; use std::fs::File; @@ -584,7 +585,7 @@ where // NB These are repr(transparent) because we pass them around as void* when compiling with LLVM. #[repr(transparent)] #[derive(Debug)] -pub(crate) struct SharedMap(pub(crate) Rc>>); +pub(crate) struct SharedMap(pub(crate) Rc>>); impl Default for SharedMap { fn default() -> SharedMap { @@ -610,7 +611,7 @@ impl SharedMap { } pub(crate) fn iter(&self, f: F) -> R where - F: FnOnce(hashbrown::hash_map::Iter) -> R, + F: FnOnce(ordermap::map::Iter<'_, K, V>) -> R, { f(self.0.borrow().iter()) } @@ -647,16 +648,16 @@ impl SharedMap { // When sending SharedMaps across threads we have to clone them and clone their contents, as Rc is // not thread-safe (and we don't want to pay the cost of Arc clones during normal execution). pub(crate) struct Shuttle(T); -impl<'a> From>>> for IntMap> { - fn from(sh: Shuttle>>) -> Self { +impl<'a> From>>> for IntMap> { + fn from(sh: Shuttle>>) -> Self { SharedMap(Rc::new(RefCell::new( sh.0.into_iter().map(|(x, y)| (x, y.into_str())).collect(), ))) } } -impl<'a> From, Int>>> for StrMap<'a, Int> { - fn from(sh: Shuttle, Int>>) -> Self { +impl<'a> From, Int>>> for StrMap<'a, Int> { + fn from(sh: Shuttle, Int>>) -> Self { SharedMap(Rc::new(RefCell::new( sh.0.into_iter().map(|(x, y)| (x.into_str(), y)).collect(), ))) @@ -664,7 +665,7 @@ impl<'a> From, Int>>> for StrMap<'a, Int> { } impl SharedMap { - fn borrow_mut(&self) -> impl std::ops::DerefMut> + '_ { + fn borrow_mut(&self) -> impl std::ops::DerefMut> + '_ { // Unlike the full std::collections APIs, we are careful not to hand out any references // internal to a SharedMap from a public function. That means that functions which mutate // the map are "Cell"-like, in that they swap out values or drop them in, but never hold @@ -699,7 +700,7 @@ impl SharedMap { impl SharedMap { pub(crate) fn get(&self, k: &K) -> V { self.borrow_mut() - .raw_entry_mut() + .raw_entry_mut_v1() .from_key(k) .or_insert_with(|| (k.clone(), V::default())) .1 @@ -708,7 +709,7 @@ impl SharedMap { } impl<'a> IntMap> { - pub(crate) fn shuttle(&self) -> Shuttle>> { + pub(crate) fn shuttle(&self) -> Shuttle>> { Shuttle( self.0 .borrow() @@ -720,7 +721,7 @@ impl<'a> IntMap> { } impl<'a> StrMap<'a, Int> { - pub(crate) fn shuttle(&self) -> Shuttle, Int>> { + pub(crate) fn shuttle(&self) -> Shuttle, Int>> { Shuttle( self.0 .borrow() @@ -740,8 +741,8 @@ impl SharedMap { } } -impl From> for SharedMap { - fn from(m: HashMap) -> SharedMap { +impl From> for SharedMap { + fn from(m: OrderMap) -> SharedMap { SharedMap(Rc::new(RefCell::new(m))) } } @@ -752,7 +753,7 @@ impl FromIterator<(K, V)> for SharedMap { T: IntoIterator, { SharedMap(Rc::new(RefCell::new( - iter.into_iter().collect::>(), + iter.into_iter().collect::>(), ))) } }