Skip to content

Commit b75351e

Browse files
authored
Optimized implementations of max, min, and clamp for bool
1 parent e286f25 commit b75351e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library/core/src/cmp.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,22 @@ mod impls {
14061406
_ => unsafe { unreachable_unchecked() },
14071407
}
14081408
}
1409+
1410+
#[inline]
1411+
fn min(self, other: bool) -> bool {
1412+
self & other
1413+
}
1414+
1415+
#[inline]
1416+
fn max(self, other: bool) -> bool {
1417+
self | other
1418+
}
1419+
1420+
#[inline]
1421+
fn clamp(self, min: bool, max: bool) -> bool {
1422+
assert!(min <= max);
1423+
self.max(min).min(max)
1424+
}
14091425
}
14101426

14111427
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

0 commit comments

Comments
 (0)