Skip to content

Commit ae37b13

Browse files
committed
Add doc-comment about assumptions in get_slice_memory_size_with_alignment fn
1 parent 1a4764f commit ae37b13

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arrow-data/src/data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ impl ArrayData {
435435
/// would return `20 * 8 = 160`.
436436
///
437437
/// The `alignment` parameter is used to add padding to each buffer being counted, to ensure
438-
/// the size for each one is aligned to `alignment` bytes (if it is `Some`)
438+
/// the size for each one is aligned to `alignment` bytes (if it is `Some`). This function
439+
/// assumes that `alignment` is a power of 2.
439440
pub fn get_slice_memory_size_with_alignment(
440441
&self,
441442
alignment: Option<u8>,
@@ -449,7 +450,7 @@ impl ArrayData {
449450
// Just pulled from arrow-ipc
450451
#[inline]
451452
fn pad_to_alignment(alignment: u8, len: usize) -> usize {
452-
let a = usize::from(alignment - 1);
453+
let a = usize::from(alignment.saturating_sub(1));
453454
((len + a) & !a) - len
454455
}
455456

0 commit comments

Comments
 (0)