You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2018/04/20 08:16:51 UTC
[arrow] branch master updated: ARROW-2471: [Rust] Builder zero
capacity fix
This is an automated email from the ASF dual-hosted git repository.
apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 46fe09a ARROW-2471: [Rust] Builder zero capacity fix
46fe09a is described below
commit 46fe09a6c9a4d7cd79f4afdae1f527fdd74e6bfb
Author: Andy Grove <an...@gmail.com>
AuthorDate: Fri Apr 20 10:16:26 2018 +0200
ARROW-2471: [Rust] Builder zero capacity fix
Author: Andy Grove <an...@gmail.com>
Closes #1911 from andygrove/builder_zero_capacity_fix and squashes the following commits:
8292bc7 <Andy Grove> fix merge conflict
589ef71 <Andy Grove> Merge remote-tracking branch 'upstream/master'
cfa7574 <Andy Grove> bug fix: it is now valid to create a builder with zero capacity and then push values to it
bd4fbb5 <Andy Grove> Merge remote-tracking branch 'upstream/master'
9c8a10a <Andy Grove> Merge remote-tracking branch 'upstream/master'
05592f8 <Andy Grove> Merge remote-tracking branch 'upstream/master'
8c0e698 <Andy Grove> Merge remote-tracking branch 'upstream/master'
31ef90b <Andy Grove> Merge remote-tracking branch 'upstream/master'
2f87c70 <Andy Grove> Fix build - add missing import
---
rust/src/array.rs | 7 +++++++
rust/src/builder.rs | 13 +++++++++++--
rust/src/list_builder.rs | 13 ++++++++++++-
rust/src/memory_pool.rs | 2 +-
4 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/rust/src/array.rs b/rust/src/array.rs
index 63d1130..55881f5 100644
--- a/rust/src/array.rs
+++ b/rust/src/array.rs
@@ -277,6 +277,13 @@ mod tests {
}
#[test]
+ fn test_from_empty_vec() {
+ let v: Vec<i32> = vec![];
+ let a = Array::from(v);
+ assert_eq!(0, a.len());
+ }
+
+ #[test]
fn test_from_optional_i32() {
let a = Array::from(vec![Some(1), None, Some(2), Some(3), None]);
assert_eq!(5, a.len());
diff --git a/rust/src/builder.rs b/rust/src/builder.rs
index 89e0004..69884cc 100644
--- a/rust/src/builder.rs
+++ b/rust/src/builder.rs
@@ -83,8 +83,9 @@ impl<T> Builder<T> {
pub fn push(&mut self, v: T) {
assert!(!self.data.is_null());
if self.len == self.capacity {
- let new_capacity = self.capacity;
- self.grow(new_capacity * 2);
+ // grow capacity by 64 bytes or double the current capacity, whichever is greater
+ let new_capacity = cmp::max(64, self.capacity * 2);
+ self.grow(new_capacity);
}
assert!(self.len < self.capacity);
unsafe {
@@ -175,6 +176,14 @@ mod tests {
}
#[test]
+ fn test_builder_i32_alloc_zero_bytes() {
+ let mut b: Builder<i32> = Builder::with_capacity(0);
+ b.push(123);
+ let a = b.finish();
+ assert_eq!(1, a.len());
+ }
+
+ #[test]
fn test_builder_i32() {
let mut b: Builder<i32> = Builder::with_capacity(5);
for i in 0..5 {
diff --git a/rust/src/list_builder.rs b/rust/src/list_builder.rs
index 96dca18..71547d2 100644
--- a/rust/src/list_builder.rs
+++ b/rust/src/list_builder.rs
@@ -55,7 +55,7 @@ mod tests {
use super::*;
#[test]
- fn test_list_u8() {
+ fn test_list_u8_default_capacity() {
let mut b: ListBuilder<u8> = ListBuilder::new();
b.push("Hello, ".as_bytes());
b.push("World!".as_bytes());
@@ -67,6 +67,17 @@ mod tests {
}
#[test]
+ fn test_list_u8_zero_capacity() {
+ let mut b: ListBuilder<u8> = ListBuilder::with_capacity(0);
+ b.push("Hello, ".as_bytes());
+ b.push("World!".as_bytes());
+ let buffer = b.finish();
+ assert_eq!(2, buffer.len());
+ assert_eq!("Hello, ".as_bytes(), buffer.slice(0));
+ assert_eq!("World!".as_bytes(), buffer.slice(1));
+ }
+
+ #[test]
fn test_empty_lists() {
let mut b: ListBuilder<u8> = ListBuilder::new();
b.push("Hello, ".as_bytes());
diff --git a/rust/src/memory_pool.rs b/rust/src/memory_pool.rs
index acfcc30..6832cd2 100644
--- a/rust/src/memory_pool.rs
+++ b/rust/src/memory_pool.rs
@@ -16,8 +16,8 @@
// under the License.
use libc;
-use std::mem;
use std::cmp;
+use std::mem;
use super::error::ArrowError;
use super::error::Result;
--
To stop receiving notification emails like this one, please contact
apitrou@apache.org.