Skip to content

Commit 963398a

Browse files
authored
Simplify power of two validation (#48)
Simplify power of two validation Use the std function instead of direct bit arithmetic.
1 parent 930ea07 commit 963398a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

blockalloc/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl Block {
4747
/// Instantiate a new block of the given size. Size must be a power of two.
4848
// ANCHOR: BlockNew
4949
pub fn new(size: BlockSize) -> Result<Block, BlockError> {
50-
// validate that size is a power of two
51-
if !(size & (size - 1) == 0) {
50+
if !size.is_power_of_two() {
5251
return Err(BlockError::BadRequest);
5352
}
5453

0 commit comments

Comments
 (0)