@@ -101,24 +101,11 @@ class OrcBackedArrowBuffer : public arrow::ResizableBuffer {
101101 ::orc::DataBuffer<T> orc_buffer_;
102102};
103103
104- arrow::Status AppendValidBytesToBitmap (arrow::ArrayBuilder* builder,
105- arrow::TypedBufferBuilder<bool >* null_bitmap_builder,
106- int64_t * length, int64_t * null_count,
107- const uint8_t * valid_bytes, int64_t valid_length) {
108- int64_t min_capacity = builder->length () + valid_length;
109- if (min_capacity > builder->capacity ()) {
110- int64_t new_capacity =
111- arrow::BufferBuilder::GrowByFactor (builder->capacity (), min_capacity);
112- ARROW_RETURN_NOT_OK (builder->arrow ::ArrayBuilder::Resize (new_capacity));
113- }
114-
115- if (valid_bytes == nullptr ) {
116- null_bitmap_builder->UnsafeAppend (valid_length, true );
117- } else {
118- null_bitmap_builder->UnsafeAppend (valid_bytes, valid_length);
119- *null_count = null_bitmap_builder->false_count ();
120- }
121- *length += valid_length;
104+ template <typename AppendToBitmap>
105+ arrow::Status AppendValidBytesToBitmap (arrow::ArrayBuilder* builder, int64_t length,
106+ AppendToBitmap append_to_bitmap) {
107+ ARROW_RETURN_NOT_OK (builder->Reserve (length));
108+ append_to_bitmap ();
122109 return arrow::Status::OK ();
123110}
124111
@@ -165,8 +152,9 @@ class UnPooledBooleanBuilder : public EmptyBuilder {
165152 }
166153
167154 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
168- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
169- valid_bytes, length);
155+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
156+ this ->UnsafeAppendToBitmap (valid_bytes, length);
157+ });
170158 }
171159
172160 arrow::Status SetData (const uint8_t * data, int64_t length) {
@@ -211,8 +199,9 @@ class UnPooledPrimitiveBuilder : public arrow::NumericBuilder<Type> {
211199 }
212200
213201 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
214- return AppendValidBytesToBitmap (this , &this ->null_bitmap_builder_ , &this ->length_ ,
215- &this ->null_count_ , valid_bytes, length);
202+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
203+ this ->UnsafeAppendToBitmap (valid_bytes, length);
204+ });
216205 }
217206
218207 arrow::Status FinishInternal (std::shared_ptr<arrow::ArrayData>* out) override {
@@ -253,8 +242,9 @@ class UnPooledLargeBinaryBuilder : public arrow::LargeBinaryBuilder {
253242 length_ += length;
254243 }
255244 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
256- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
257- valid_bytes, length);
245+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
246+ this ->UnsafeAppendToBitmap (valid_bytes, length);
247+ });
258248 }
259249 arrow::Status FinishInternal (std::shared_ptr<arrow::ArrayData>* out) override {
260250 std::shared_ptr<arrow::Buffer> null_bitmap;
@@ -299,8 +289,9 @@ class UnPooledBinaryBuilder : public arrow::BinaryBuilder {
299289 }
300290
301291 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
302- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
303- valid_bytes, length);
292+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
293+ this ->UnsafeAppendToBitmap (valid_bytes, length);
294+ });
304295 }
305296
306297 arrow::Status FinishInternal (std::shared_ptr<arrow::ArrayData>* out) override {
@@ -340,8 +331,9 @@ class UnPooledListBuilder : public EmptyBuilder {
340331 }
341332
342333 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
343- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
344- valid_bytes, length);
334+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
335+ this ->UnsafeAppendToBitmap (valid_bytes, length);
336+ });
345337 }
346338
347339 void SetOffsets (const std::shared_ptr<arrow::Buffer>& offsets) {
@@ -389,8 +381,9 @@ class UnPooledStructBuilder : public EmptyBuilder {
389381 }
390382
391383 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
392- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
393- valid_bytes, length);
384+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
385+ this ->UnsafeAppendToBitmap (valid_bytes, length);
386+ });
394387 }
395388
396389 arrow::Status FinishInternal (std::shared_ptr<arrow::ArrayData>* out) override {
@@ -516,8 +509,9 @@ class UnPooledStringDictionaryBuilder : public EmptyBuilder {
516509 indices_ = indices;
517510 }
518511 arrow::Status SetNulls (const uint8_t * valid_bytes, int64_t length) {
519- return AppendValidBytesToBitmap (this , &null_bitmap_builder_, &length_, &null_count_,
520- valid_bytes, length);
512+ return AppendValidBytesToBitmap (this , length, [this , valid_bytes, length] {
513+ this ->UnsafeAppendToBitmap (valid_bytes, length);
514+ });
521515 }
522516 arrow::Status FinishInternal (std::shared_ptr<arrow::ArrayData>* out) override {
523517 std::shared_ptr<arrow::Buffer> null_bitmap;
0 commit comments