mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Optimized implementations of max, min, and clamp for bool
This commit is contained in:
parent
e286f25ec0
commit
b75351e98e
@ -1406,6 +1406,22 @@ mod impls {
|
||||
_ => unsafe { unreachable_unchecked() },
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn min(self, other: bool) -> bool {
|
||||
self & other
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn max(self, other: bool) -> bool {
|
||||
self | other
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clamp(self, min: bool, max: bool) -> bool {
|
||||
assert!(min <= max);
|
||||
self.max(min).min(max)
|
||||
}
|
||||
}
|
||||
|
||||
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
|
Loading…
Reference in New Issue
Block a user