Skip to content

Commit 12263da

Browse files
committed
Add a section on copied.
Fixes #83.
1 parent c5ccb2e commit 12263da

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/iterators.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ The same is true for related iterators:
7878
[`slice::rchunks_exact_mut`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.rchunks_exact_mut
7979
[`RChunksExactMut::into_remainder`]: https://doc.rust-lang.org/stable/std/slice/struct.RChunksExactMut.html#method.into_remainder
8080

81+
## `copied`
82+
83+
When iterating over collections of small data types, such as integers, it may
84+
be better to use `iter().copied()` instead of `iter()`. Whatever consumes that
85+
iterator will receive the integers by value instead of by reference, and LLVM
86+
may generate better code in that case.
87+
[**Example 1**](https://github.com/rust-lang/rust/issues/106539),
88+
[**Example 2**](https://github.com/rust-lang/rust/issues/113789).
89+
90+
This is an advanced technique. You might need to check the generated machine
91+
code to be certain it is having an effect. See the [Machine
92+
Code](machine-code.md) chapter for details on how to do that.

0 commit comments

Comments
 (0)