diff --git a/Cargo.toml b/Cargo.toml index b83a49a1c6e..65ce69581c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ unicode-width = "0.1" textwrap = "0.11" indexmap = "1.0" os_str_bytes = "2.1" +vec_map = "0.8" strsim = { version = "0.10", optional = true } yaml-rust = { version = "0.4.1", optional = true } atty = { version = "0.2", optional = true } termcolor = { version = "1.1", optional = true } -vec_map = { version = "0.8", optional = true } term_size = { version = "1.0.0-beta1", optional = true } lazy_static = { version = "1", optional = true } clap_derive = { path = "./clap_derive", version = "3.0.0-beta.1", optional = true } @@ -80,7 +80,7 @@ version-sync = "0.8" criterion = { git = "git://github.com/pksunkara/criterion.rs", version = "0.3" } [features] -default = ["suggestions", "color", "vec_map", "derive", "std", "cargo"] +default = ["suggestions", "color", "derive", "std", "cargo"] std = [] # support for no_std in a backwards-compatible way suggestions = ["strsim"] color = ["atty", "termcolor"] diff --git a/src/lib.rs b/src/lib.rs index 170feb4a802..a2856188d11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -320,7 +320,6 @@ //! * `derive`: Enables the custom derive (i.e. `#[derive(Clap)]`). Without this you must use one of the other methods of creating a `clap` CLI listed above //! * `suggestions`: Turns on the `Did you mean '--myoption'?` feature for when users make typos. (builds dependency `strsim`) //! * `color`: Turns on colored error messages. This feature only works on non-Windows OSs. (builds dependency `ansi-term`) -//! * `vec_map`: Use [`VecMap`](https://crates.io/crates/vec_map) internally instead of a [`BTreeMap`](https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html). This feature provides a _slight_ performance improvement. (builds dependency `vec_map`) //! //! To disable these, add this to your `Cargo.toml`: //! diff --git a/src/parse/parser.rs b/src/parse/parser.rs index c03842a0e46..25b52ecce29 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -127,16 +127,10 @@ where // Because you must wait until all arguments have been supplied, this is the first chance // to make assertions on positional argument indexes // - // Firt we verify that the index highest supplied index, is equal to the number of + // First we verify that the index highest supplied index, is equal to the number of // positional arguments to verify there are no gaps (i.e. supplying an index of 1 and 3 // but no 2) - // #[cfg(feature = "vec_map")] - // fn _highest_idx(map: &VecMap<&str>) -> usize { map.keys().last().unwrap_or(0) } - - // #[cfg(not(feature = "vec_map"))] - // fn _highest_idx(map: &VecMap<&str>) -> usize { *map.keys().last().unwrap_or(&0) } - let highest_idx = *self .app .args diff --git a/src/util/map.rs b/src/util/map.rs deleted file mode 100644 index aa4d2086524..00000000000 --- a/src/util/map.rs +++ /dev/null @@ -1,92 +0,0 @@ -#[cfg(feature = "vec_map")] -pub(crate) use vec_map::VecMap; - -#[cfg(not(feature = "vec_map"))] -pub(crate) use self::vec_map::VecMap; - -#[cfg(not(feature = "vec_map"))] -mod vec_map { - use std::collections::btree_map; - use std::collections::BTreeMap; - use std::fmt::{self, Debug, Formatter}; - - #[derive(Clone, Default, Debug)] - pub(crate) struct VecMap { - inner: BTreeMap, - } - - impl VecMap { - pub(crate) fn new() -> Self { - VecMap { - inner: Default::default(), - } - } - - pub(crate) fn len(&self) -> usize { - self.inner.len() - } - - pub(crate) fn is_empty(&self) -> bool { - self.inner.is_empty() - } - - pub(crate) fn insert(&mut self, key: usize, value: V) -> Option { - self.inner.insert(key, value) - } - - pub(crate) fn values(&self) -> Values { - self.inner.values() - } - - pub(crate) fn keys(&self) -> btree_map::Keys { - self.inner.keys() - } - - pub(crate) fn iter(&self) -> Iter { - Iter { - inner: self.inner.iter(), - } - } - - pub(crate) fn contains_key(&self, key: usize) -> bool { - self.inner.contains_key(&key) - } - - pub(crate) fn entry(&mut self, key: usize) -> Entry { - self.inner.entry(key) - } - - pub(crate) fn get(&self, key: usize) -> Option<&V> { - self.inner.get(&key) - } - } - - pub(crate) type Values<'a, V> = btree_map::Values<'a, usize, V>; - - pub(crate) type Entry<'a, V> = btree_map::Entry<'a, usize, V>; - - #[derive(Clone)] - pub(crate) struct Iter<'a, V: 'a> { - inner: btree_map::Iter<'a, usize, V>, - } - - impl<'a, V: 'a + Debug> Debug for Iter<'a, V> { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_list().entries(self.inner.clone()).finish() - } - } - - impl<'a, V: 'a> Iterator for Iter<'a, V> { - type Item = (usize, &'a V); - - fn next(&mut self) -> Option { - self.inner.next().map(|(k, v)| (*k, v)) - } - } - - impl<'a, V: 'a> DoubleEndedIterator for Iter<'a, V> { - fn next_back(&mut self) -> Option { - self.inner.next_back().map(|(k, v)| (*k, v)) - } - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index b92a0efefa6..ab04ca7fd03 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -4,12 +4,12 @@ mod argstr; mod fnv; mod graph; mod id; -mod map; mod strext; pub use self::fnv::Key; -pub(crate) use self::{argstr::ArgStr, graph::ChildGraph, id::Id, map::VecMap}; +pub(crate) use self::{argstr::ArgStr, graph::ChildGraph, id::Id}; +pub(crate) use vec_map::VecMap; #[cfg(feature = "color")] pub(crate) use termcolor;