Skip to content

Commit 2eabb59

Browse files
authored
perf: Use Vec::with_capacity in cast_to_run_end_encoded (#8726)
Related to #8707. Inspired by #8716 (comment), a follow up improvement to #8589: We already know what the length of the two vectors will be, so we can create them with that capacity.
1 parent 1b18582 commit 2eabb59

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arrow-cast/src/cast/run_array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ pub(crate) fn cast_to_run_end_encoded<K: RunEndIndexType>(
136136

137137
// Partition the array to identify runs of consecutive equal values
138138
let partitions = partition(&[Arc::clone(cast_array)])?;
139-
let mut run_ends = Vec::new();
140-
let mut values_indexes = Vec::new();
139+
let size = partitions.len();
140+
let mut run_ends = Vec::with_capacity(size);
141+
let mut values_indexes = Vec::with_capacity(size);
141142
let mut last_partition_end = 0;
142143
for partition in partitions.ranges() {
143144
values_indexes.push(last_partition_end);

0 commit comments

Comments
 (0)