Skip to content

Commit 4385eb3

Browse files
committed
Inline copied and next methods
1 parent 999ac5f commit 4385eb3

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

library/core/src/iter/adapters/copied.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ where
4343
{
4444
type Item = T;
4545

46+
#[inline]
4647
fn next(&mut self) -> Option<T> {
4748
self.it.next().copied()
4849
}

library/core/src/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ impl<T> Option<&T> {
17941794
/// let copied = opt_x.copied();
17951795
/// assert_eq!(copied, Some(12));
17961796
/// ```
1797+
#[inline]
17971798
#[must_use = "`self` will be dropped if the result is not used"]
17981799
#[stable(feature = "copied", since = "1.35.0")]
17991800
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: -C opt-level=3
2+
3+
#![crate_type = "lib"]
4+
5+
extern crate core;
6+
use core::{iter::Copied, slice::Iter};
7+
8+
// Make sure that the use of unwrap_unchecked is optimized accordingly.
9+
// i.e., there are no branch jumps.
10+
pub unsafe fn unwrap_unchecked_optimized(x: &mut Copied<Iter<'_, u32>>) -> u32 {
11+
// CHECK-NOT: br
12+
x.next().unwrap_unchecked()
13+
}

0 commit comments

Comments
 (0)