diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-12-23 18:47:04 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-12-23 18:54:10 +0100 |
commit | eb85a2ba79a1a9e562e08d0cd6dd0c9e55d6f05b (patch) | |
tree | 49f217ff468a341995ae722d404d120c5bb333b9 | |
parent | 6bb16ba6971601ffe277830344552ba71e431b52 (diff) |
regex_set: Avoid allocations in unmatched_items().
-rw-r--r-- | src/regex_set.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/regex_set.rs b/src/regex_set.rs index 3e77e064..a0b34bb6 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -32,15 +32,16 @@ impl RegexSet { &self.items[..] } - /// Returns regexes in the set which didn't match any strings yet - pub fn unmatched_items(&self) -> Vec<String> { - let mut items = vec![]; - for (i, item) in self.items.iter().enumerate() { - if !self.matched[i].get() { - items.push(item.clone()); + /// Returns an iterator over regexes in the set which didn't match any + /// strings yet. + pub fn unmatched_items(&self) -> impl Iterator<Item = &String> { + self.items.iter().enumerate().filter_map(move |(i, item)| { + if self.matched[i].get() { + return None; } - } - items + + Some(item) + }) } /// Construct a RegexSet from the set of entries we've accumulated. |