From 3cb4a48ebd15c20692f4f3a2a924284dc7fd5e10 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Fri, 4 Sep 2015 14:05:13 -0400 Subject: [PATCH] perf: changes ArgGroup HashSets to Vec --- src/app/app.rs | 4 ++-- src/args/group.rs | 45 ++++++++++++--------------------------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/app/app.rs b/src/app/app.rs index 51c492ac637..58c4cdee478 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -713,7 +713,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ } if let Some(grp) = a.group { let ag = self.groups.entry(grp).or_insert(ArgGroup::with_name(grp)); - ag.args.insert(a.name); + ag.args.push(a.name); } if let Some(s) = a.short { if self.short_list.contains(&s) { @@ -1094,7 +1094,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ let mut found = false; if let Some(ref mut grp) = self.groups.get_mut(group.name) { for a in &group.args { - grp.args.insert(a); + grp.args.push(a); } grp.requires = group.requires.clone(); grp.conflicts = group.conflicts.clone(); diff --git a/src/args/group.rs b/src/args/group.rs index 3327a6cb9d8..cf98916f742 100644 --- a/src/args/group.rs +++ b/src/args/group.rs @@ -1,6 +1,5 @@ #[cfg(feature = "yaml")] use std::collections::BTreeMap; -use std::collections::HashSet; use std::fmt::{Debug, Formatter, Result}; #[cfg(feature = "yaml")] @@ -46,13 +45,13 @@ pub struct ArgGroup<'n, 'ar> { #[doc(hidden)] pub name: &'n str, #[doc(hidden)] - pub args: HashSet<&'ar str>, + pub args: Vec<&'ar str>, #[doc(hidden)] pub required: bool, #[doc(hidden)] - pub requires: Option>, + pub requires: Option>, #[doc(hidden)] - pub conflicts: Option> + pub conflicts: Option> } impl<'n, 'ar> ArgGroup<'n, 'ar> { @@ -71,7 +70,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> { ArgGroup { name: n, required: false, - args: HashSet::new(), + args: vec![], requires: None, conflicts: None } @@ -141,7 +140,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> { /// .add("config") /// # ).get_matches(); pub fn add(mut self, n: &'ar str) -> Self { - self.args.insert(n); + self.args.push(n); self } @@ -202,11 +201,9 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> { /// # ).get_matches(); pub fn requires(mut self, n: &'ar str) -> Self { if let Some(ref mut reqs) = self.requires { - reqs.insert(n); + reqs.push(n); } else { - let mut hs = HashSet::new(); - hs.insert(n); - self.requires = Some(hs); + self.requires = Some(vec![n]); } self } @@ -252,11 +249,9 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> { /// # ).get_matches(); pub fn conflicts_with(mut self, n: &'ar str) -> Self { if let Some(ref mut confs) = self.conflicts { - confs.insert(n); + confs.push(n); } else { - let mut hs = HashSet::new(); - hs.insert(n); - self.conflicts = Some(hs); + self.conflicts = Some(vec![n]); } self } @@ -300,7 +295,6 @@ impl<'n, 'ar> Debug for ArgGroup<'n, 'ar> { #[cfg(test)] mod test { use super::ArgGroup; - use std::collections::HashSet; #[test] fn groups() { @@ -316,24 +310,9 @@ mod test { .requires_all(&["r2", "r3"]) .requires("r4"); - let mut args = HashSet::new(); - args.insert("a1"); - args.insert("a2"); - args.insert("a3"); - args.insert("a4"); - - let mut reqs = HashSet::new(); - reqs.insert("r1"); - reqs.insert("r2"); - reqs.insert("r3"); - reqs.insert("r4"); - - let mut confs = HashSet::new(); - confs.insert("c1"); - confs.insert("c2"); - confs.insert("c3"); - confs.insert("c4"); - + let args = vec!["a1", "a2", "a3", "a4"]; + let reqs = vec!["r1", "r2", "r3", "r4"]; + let confs = vec!["c1", "c2", "c3", "c4"]; assert_eq!(g.args, args); assert_eq!(g.requires.unwrap(), reqs);