From ea5d696d5504eb8f122d617ca1a970d9a031ac17 Mon Sep 17 00:00:00 2001 From: Nick Rolfe Date: Mon, 1 Nov 2021 19:16:50 +0000 Subject: [PATCH] Ruby: use IndexMap This is the same idea as Java's LinkedHashMap: it gives the same O(1) insertion and lookup as HashMap, but preserves insertion order for iteration. --- ruby/Cargo.lock | Bin 16591 -> 17035 bytes ruby/extractor/Cargo.toml | 1 + ruby/extractor/src/extractor.rs | 4 ++-- ruby/extractor/src/trap.rs | 10 +++++----- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ruby/Cargo.lock b/ruby/Cargo.lock index f2233f300722465b0370d754babab3b89a6d4a95..649bc74b269933a70bd2437b5cfabb1c9a3c399f 100644 GIT binary patch delta 239 zcmY+9J4!=A6hL{EpGuxc)F31Q+c2Md@5~gE!WAStn7MO@q{xdTpcXb3R(8%tgmiAg zEo3Q4p+&0G95|fc_vZ7X`Ih!3Zsuvddg(^z&$8YuR^8xXFj8Z!YjZc9#Dr2*hMkKe^W+6Thond6J9R?%8cq|A6#fzunQ$E;Khs|}(?XK5ld0ob*qlg~6x;vRon5-p* zfS?U#VMs(CEIC`0W|xaeK7b3!8c~wTf`E-db17sZ*6GFYZ2rIT)xX_7UcR-bi@)Ud I=l-g{2Z-oLfdBvi delta 23 fcmeBfWjx==xFJ<&vbym7&7Vc8g*I2K3rGV1bAbr` diff --git a/ruby/extractor/Cargo.toml b/ruby/extractor/Cargo.toml index efc5a12159d..2cdf20ac50d 100644 --- a/ruby/extractor/Cargo.toml +++ b/ruby/extractor/Cargo.toml @@ -18,3 +18,4 @@ tracing-subscriber = { version = "0.2", features = ["env-filter"] } rayon = "1.5.0" num_cpus = "1.13.0" regex = "1.4.3" +indexmap = "1.7.0" \ No newline at end of file diff --git a/ruby/extractor/src/extractor.rs b/ruby/extractor/src/extractor.rs index 1f7e845bc1b..8170d677082 100644 --- a/ruby/extractor/src/extractor.rs +++ b/ruby/extractor/src/extractor.rs @@ -1,6 +1,6 @@ use crate::trap; +use indexmap::IndexMap; use node_types::{EntryKind, Field, NodeTypeMap, Storage, TypeName}; -use std::collections::BTreeMap as Map; use std::fmt; use std::path::Path; @@ -407,7 +407,7 @@ impl<'a> Visitor<'a> { child_nodes: &[ChildNode], parent_id: trap::Label, ) -> Option> { - let mut map: Map<&Option, (&Field, Vec)> = Map::new(); + let mut map: IndexMap<&Option, (&Field, Vec)> = IndexMap::new(); for field in fields { map.insert(&field.name, (field, Vec::new())); } diff --git a/ruby/extractor/src/trap.rs b/ruby/extractor/src/trap.rs index 8fbe0e52801..8e9b90c23d1 100644 --- a/ruby/extractor/src/trap.rs +++ b/ruby/extractor/src/trap.rs @@ -1,22 +1,22 @@ use std::borrow::Cow; -use std::collections::BTreeMap; use std::fmt; use std::io::BufWriter; use std::path::Path; use flate2::write::GzEncoder; +use indexmap::IndexMap; pub struct Writer { /// Labels that should be assigned fresh ids, e.g. `#123=*`. fresh_ids: Vec