Skip to content

Commit 38013e7

Browse files
committed
Use iter::from_fn in String::remove_matches
1 parent 3740ba2 commit 38013e7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

library/alloc/src/string.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use core::fmt;
4848
use core::hash;
4949
#[cfg(not(no_global_oom_handling))]
5050
use core::iter::FromIterator;
51-
use core::iter::FusedIterator;
51+
use core::iter::{from_fn, FusedIterator};
5252
#[cfg(not(no_global_oom_handling))]
5353
use core::ops::Add;
5454
#[cfg(not(no_global_oom_handling))]
@@ -1290,15 +1290,9 @@ impl String {
12901290
{
12911291
use core::str::pattern::Searcher;
12921292

1293-
let matches = {
1293+
let matches: Vec<_> = {
12941294
let mut searcher = pat.into_searcher(self);
1295-
let mut matches = Vec::new();
1296-
1297-
while let Some(m) = searcher.next_match() {
1298-
matches.push(m);
1299-
}
1300-
1301-
matches
1295+
from_fn(|| searcher.next_match()).collect()
13021296
};
13031297

13041298
let len = self.len();

0 commit comments

Comments
 (0)