You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/03/16 22:23:23 UTC
arrow git commit: ARROW-231 [C++]: Add typed Resize to PoolBuffer
Repository: arrow
Updated Branches:
refs/heads/master 0cf2bbb2a -> 867f92470
ARROW-231 [C++]: Add typed Resize to PoolBuffer
I also added a typed Reserve to be consistent. Let me know what you think.
Author: Johan Mabille <jo...@gmail.com>
Closes #391 from JohanMabille/buffer_resize and squashes the following commits:
90ccbfa [Johan Mabille] typed resize
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/867f9247
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/867f9247
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/867f9247
Branch: refs/heads/master
Commit: 867f92470597a41ccef44bc145c979f0d396387c
Parents: 0cf2bbb
Author: Johan Mabille <jo...@gmail.com>
Authored: Thu Mar 16 18:23:16 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Thu Mar 16 18:23:16 2017 -0400
----------------------------------------------------------------------
cpp/src/arrow/buffer-test.cc | 19 +++++++++++++++++++
cpp/src/arrow/buffer.h | 10 ++++++++++
2 files changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/867f9247/cpp/src/arrow/buffer-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/buffer-test.cc b/cpp/src/arrow/buffer-test.cc
index 934fcfe..e0a2137 100644
--- a/cpp/src/arrow/buffer-test.cc
+++ b/cpp/src/arrow/buffer-test.cc
@@ -66,6 +66,25 @@ TEST_F(TestBuffer, Resize) {
ASSERT_EQ(128, buf.capacity());
}
+TEST_F(TestBuffer, TypedResize) {
+ PoolBuffer buf;
+
+ ASSERT_EQ(0, buf.size());
+ ASSERT_OK(buf.TypedResize<double>(100));
+ ASSERT_EQ(800, buf.size());
+ ASSERT_OK(buf.TypedResize<double>(200));
+ ASSERT_EQ(1600, buf.size());
+
+ ASSERT_OK(buf.TypedResize<double>(50, true));
+ ASSERT_EQ(400, buf.size());
+ ASSERT_EQ(448, buf.capacity());
+
+ ASSERT_OK(buf.TypedResize<double>(100));
+ ASSERT_EQ(832, buf.capacity());
+ ASSERT_OK(buf.TypedResize<double>(50, false));
+ ASSERT_EQ(832, buf.capacity());
+}
+
TEST_F(TestBuffer, ResizeOOM) {
// This test doesn't play nice with AddressSanitizer
#ifndef ADDRESS_SANITIZER
http://git-wip-us.apache.org/repos/asf/arrow/blob/867f9247/cpp/src/arrow/buffer.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/buffer.h b/cpp/src/arrow/buffer.h
index 26c8ea6..1647e86 100644
--- a/cpp/src/arrow/buffer.h
+++ b/cpp/src/arrow/buffer.h
@@ -133,6 +133,16 @@ class ARROW_EXPORT ResizableBuffer : public MutableBuffer {
/// It does not change buffer's reported size.
virtual Status Reserve(int64_t new_capacity) = 0;
+ template <class T>
+ Status TypedResize(int64_t new_nb_elements, bool shrink_to_fit = true) {
+ return Resize(sizeof(T) * new_nb_elements, shrink_to_fit);
+ }
+
+ template <class T>
+ Status TypedReserve(int64_t new_nb_elements) {
+ return Reserve(sizeof(T) * new_nb_elements);
+ }
+
protected:
ResizableBuffer(uint8_t* data, int64_t size) : MutableBuffer(data, size) {}
};