Skip to content

Commit 3697121

Browse files
committed
auto merge of #11568 : FlaPer87/rust/even, r=alexcrichton
This implementation should be a bit more optimal than calling `self.is_multiple_of(&2)`
2 parents 149fc76 + 515978d commit 3697121

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/libstd/num/int_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl Integer for $T {
308308

309309
/// Returns `true` if the number is divisible by `2`
310310
#[inline]
311-
fn is_even(&self) -> bool { self.is_multiple_of(&2) }
311+
fn is_even(&self) -> bool { self & 1 == 0 }
312312

313313
/// Returns `true` if the number is not divisible by `2`
314314
#[inline]

src/libstd/num/uint_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Integer for $T {
169169

170170
/// Returns `true` if the number is divisible by `2`
171171
#[inline]
172-
fn is_even(&self) -> bool { self.is_multiple_of(&2) }
172+
fn is_even(&self) -> bool { self & 1 == 0 }
173173

174174
/// Returns `true` if the number is not divisible by `2`
175175
#[inline]

0 commit comments

Comments
 (0)