Skip to content

Commit

Permalink
tracer: use BTreeMap to make env sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed May 5, 2024
1 parent 66f98ce commit 8243758
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::RefCell,
collections::HashMap,
collections::BTreeMap,
ffi::OsStr,
io::{self, Write},
path::Path,
Expand Down Expand Up @@ -357,7 +357,7 @@ impl Printer {
&self,
state: &ProcessState,
result: i64,
env: &HashMap<String, String>,
env: &BTreeMap<String, String>,
cwd: &Path,
) -> color_eyre::Result<()> {
// Preconditions:
Expand Down
16 changes: 8 additions & 8 deletions src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::fmt;
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap, HashSet},
collections::{BTreeMap, BTreeSet, HashSet},
ffi::CString,
fmt::{Display, Formatter},
io::{self, BufRead, BufReader, Read},
Expand Down Expand Up @@ -290,9 +290,9 @@ pub fn parse_env_entry(item: &str) -> (&str, &str) {

#[derive(Debug, Clone, PartialEq)]
pub struct EnvDiff {
pub added: HashMap<String, String>,
pub removed: HashSet<String>,
pub modified: HashMap<String, String>,
pub added: BTreeMap<String, String>,
pub removed: BTreeSet<String>,
pub modified: BTreeMap<String, String>,
}

impl EnvDiff {
Expand All @@ -301,9 +301,9 @@ impl EnvDiff {
}
}

pub fn diff_env(original: &HashMap<String, String>, envp: &[String]) -> EnvDiff {
let mut added = HashMap::new();
let mut modified = HashMap::new();
pub fn diff_env(original: &BTreeMap<String, String>, envp: &[String]) -> EnvDiff {
let mut added = BTreeMap::new();
let mut modified = BTreeMap::new();
// Use str to avoid cloning all env vars
let mut removed: HashSet<&str> = original.keys().map(|v| v.as_str()).collect();
for entry in envp.iter() {
Expand All @@ -329,7 +329,7 @@ pub fn diff_env(original: &HashMap<String, String>, envp: &[String]) -> EnvDiff
#[derive(Debug, Clone)]
pub struct BaselineInfo {
pub cwd: PathBuf,
pub env: HashMap<String, String>,
pub env: BTreeMap<String, String>,
pub fdinfo: FileDescriptorInfoCollection,
}

Expand Down
4 changes: 2 additions & 2 deletions src/tracer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::HashMap,
collections::BTreeMap,
ffi::CString,
io::{self, stdin},
os::fd::AsRawFd,
Expand Down Expand Up @@ -724,7 +724,7 @@ impl Tracer {

// This function does not take self due to borrow checker
fn collect_exec_event(
env: &HashMap<String, String>,
env: &BTreeMap<String, String>,
state: &ProcessState,
result: i64,
) -> Box<ExecEvent> {
Expand Down

0 comments on commit 8243758

Please sign in to comment.