jhorstmann commented on code in PR #5417:
URL: https://github.com/apache/arrow-rs/pull/5417#discussion_r1499086593


##########
arrow-buffer/src/util/bit_util.rs:
##########
@@ -39,7 +39,12 @@ pub fn round_upto_multiple_of_64(num: usize) -> usize {
 /// be a power of 2.
 pub fn round_upto_power_of_2(num: usize, factor: usize) -> usize {
     debug_assert!(factor > 0 && (factor & (factor - 1)) == 0);
-    (num + (factor - 1)) & !(factor - 1)
+    let rounded = (num.saturating_add(factor - 1)) & !(factor - 1);

Review Comment:
   I would maybe go with `checked_add` instead of saturation + assert:
   
   ```
   (num.checked_add(factor - 1).expect("failed to round to next power of 2")) & 
!(factor - 1)
   ```
   
   The formatting of the assert message bloats the assembly a little bit. This 
is probably not an issue, but might interact with inlining decisions via 
`MutableBuffer::push -> MutableBuffer::reserve -> round_upto_multiple_of_64`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to