Skip to content

Commit 4f9fee3

Browse files
committed
Minor: reserve output space in ByteViewArrayDecoderDictionary
1 parent a01886d commit 4f9fee3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

parquet/src/arrow/array_reader/byte_view_array.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,13 @@ impl ByteViewArrayDecoderDictionary {
432432
}
433433
}
434434

435-
/// Reads the next indexes from self.decoder
436-
/// the indexes are assumed to be indexes into `dict`
435+
/// Reads the next `len` indexes from self.decoder
436+
///
437+
/// The indexes are assumed to be indexes into `dict`
437438
/// the output values are written to output
438439
///
439-
/// Assumptions / Optimization
440+
/// # Assumptions / Optimization
441+
///
440442
/// This function checks if dict.buffers() are the last buffers in `output`, and if so
441443
/// reuses the dictionary page buffers directly without copying data
442444
fn read(&mut self, output: &mut ViewBuffer, dict: &ViewBuffer, len: usize) -> Result<usize> {
@@ -458,6 +460,10 @@ impl ByteViewArrayDecoderDictionary {
458460
}
459461
};
460462

463+
// we are going to append `len` views to the output buffer so reserve
464+
// the space for them to avoid reallocations
465+
output.reserve_views(len);
466+
461467
if need_to_create_new_buffer {
462468
for b in dict.buffers.iter() {
463469
output.buffers.push(b.clone());

parquet/src/arrow/buffer/view_buffer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ impl ViewBuffer {
3737
self.views.is_empty()
3838
}
3939

40+
/// Reserve capacity for `additional` views
41+
pub fn reserve_views(&mut self, additional: usize) {
42+
self.views.reserve(additional);
43+
}
44+
4045
pub fn append_block(&mut self, block: Buffer) -> u32 {
4146
let block_id = self.buffers.len() as u32;
4247
self.buffers.push(block);

0 commit comments

Comments
 (0)