about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-03-26 10:38:32 -0400
committerTamir Duberstein <tamird@google.com>2021-06-06 08:06:03 -0400
commit38013e708eb6ec5abe9992078857b147ff3b58d5 (patch)
treedef3faf2c323d71326df490cfe6caa4fac08f4cf /library/alloc/src/string.rs
parent3740ba2a7dd965ca45db500ebf7ad580a7812c07 (diff)
Use iter::from_fn in String::remove_matches
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index dbe5bc1da46..4aa2be2b178 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -48,7 +48,7 @@ use core::fmt;
 use core::hash;
 #[cfg(not(no_global_oom_handling))]
 use core::iter::FromIterator;
-use core::iter::FusedIterator;
+use core::iter::{from_fn, FusedIterator};
 #[cfg(not(no_global_oom_handling))]
 use core::ops::Add;
 #[cfg(not(no_global_oom_handling))]
@@ -1290,15 +1290,9 @@ impl String {
     {
         use core::str::pattern::Searcher;
 
-        let matches = {
+        let matches: Vec<_> = {
             let mut searcher = pat.into_searcher(self);
-            let mut matches = Vec::new();
-
-            while let Some(m) = searcher.next_match() {
-                matches.push(m);
-            }
-
-            matches
+            from_fn(|| searcher.next_match()).collect()
         };
 
         let len = self.len();