apache / arrow

Apache Arrow is a multi-language toolbox for accelerated data interchange and in-memory processing
https://arrow.apache.org/
Apache License 2.0
14.3k stars 3.48k forks source link

Rust: ListBuilder::with_capacity should allocate 1 more element for offsets? #1983

Closed kanekv closed 6 years ago

kanekv commented 6 years ago
    /// Create a ListBuilder with the specified capacity
    pub fn with_capacity(n: usize) -> Self {
        let data = Builder::with_capacity(n);
        let mut offsets = Builder::with_capacity(n);
        offsets.push(0_i32);
        ListBuilder { data, offsets }
    }

When creating ListBuilder with_capacity shouldn't we allocate 1 more element for offsets because we are pushing 0 element there immediately? @andygrove

andygrove commented 6 years ago

Well spotted! I actually just noticed that myself yesterday. The builder does grow as needed but yes it would be much more efficient to allocate the correct size. Would you like to create a PR to fix this? If not, I'll get to it soon.

kanekv commented 6 years ago

@andygrove I'll do PR in a bit, thanks!