We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3740ba2 commit 38013e7Copy full SHA for 38013e7
library/alloc/src/string.rs
@@ -48,7 +48,7 @@ use core::fmt;
48
use core::hash;
49
#[cfg(not(no_global_oom_handling))]
50
use core::iter::FromIterator;
51
-use core::iter::FusedIterator;
+use core::iter::{from_fn, FusedIterator};
52
53
use core::ops::Add;
54
@@ -1290,15 +1290,9 @@ impl String {
1290
{
1291
use core::str::pattern::Searcher;
1292
1293
- let matches = {
+ let matches: Vec<_> = {
1294
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
+ from_fn(|| searcher.next_match()).collect()
1302
};
1303
1304
let len = self.len();
0 commit comments