Skip to content

Commit bdae026

Browse files
committed
Optimize FromIterator by using fold.
If you're curious why this works, see [1]. The benchmark results on Rust 1.42.0: simple iterator time: [5.3103 ns 5.3130 ns 5.3161 ns] change: [+0.7242% +1.1547% +1.5162%] (p = 0.00 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 7 (7.00%) high mild 5 (5.00%) high severe chained iterator time: [15.553 ns 15.566 ns 15.576 ns] change: [-15.667% -15.456% -15.270%] (p = 0.00 < 0.05) Performance has improved. [1]: https://medium.com/@veedrac/rust-is-slow-and-i-am-the-cure-32facc0fdcb
1 parent b5bfd08 commit bdae026

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

enumflags/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ where
378378
where
379379
I: IntoIterator<Item = B>
380380
{
381-
let mut flags = BitFlags::empty();
382-
for flag in it {
383-
flags |= flag.into();
384-
}
385-
flags
381+
it.into_iter().fold(BitFlags::empty(), |acc, flag| acc | flag)
386382
}
387383
}
388384

0 commit comments

Comments
 (0)