Skip to content

Commit

Permalink
Use iter::from_fn in String::remove_matches
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Jun 6, 2021
1 parent 3740ba2 commit 38013e7
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions library/alloc/src/string.rs
Expand Up @@ -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))]
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 38013e7

Please sign in to comment.