mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
replace | with || in {unsigned_int}::borrowing_sub
Using short-circuiting operators makes it easier to perform some kinds of source code analysis, like MC/DC code coverage (a requirement in safety-critical environments). The optimized x86_64 assembly is the same between the old and new versions: ``` mov eax, edi add dl, -1 sbb eax, esi setb dl ret ```
This commit is contained in:
@@ -1606,7 +1606,7 @@ pub const fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool) {
|
||||
// to generate optimal code for now, and LLVM doesn't have an equivalent intrinsic
|
||||
let (a, b) = self.overflowing_sub(rhs);
|
||||
let (c, d) = a.overflowing_sub(borrow as $SelfT);
|
||||
(c, b | d)
|
||||
(c, b || d)
|
||||
}
|
||||
|
||||
/// Computes the absolute difference between `self` and `other`.
|
||||
|
||||
Reference in New Issue
Block a user