Skip to content

Commit 5bfae36

Browse files
ritchie46alamb
authored andcommitted
ARROW-12165: [Rust] inline append functions of builders
The `append` functions in the `Builder` structs are often used in "hot" code. This PR tags them with `#[inline]`, making it possible to inline the function calls across crate boundaries. Closes #9860 from ritchie46/inline_builder_appends Authored-by: Ritchie Vink <[email protected]> Signed-off-by: Andrew Lamb <[email protected]>
1 parent af4d5f4 commit 5bfae36

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

rust/arrow/src/array/builder.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,23 @@ impl BooleanBuilder {
433433
}
434434

435435
/// Appends a value of type `T` into the builder
436+
#[inline]
436437
pub fn append_value(&mut self, v: bool) -> Result<()> {
437438
self.bitmap_builder.append(true);
438439
self.values_builder.append(v);
439440
Ok(())
440441
}
441442

442443
/// Appends a null slot into the builder
444+
#[inline]
443445
pub fn append_null(&mut self) -> Result<()> {
444446
self.bitmap_builder.append(false);
445447
self.values_builder.advance(1);
446448
Ok(())
447449
}
448450

449451
/// Appends an `Option<T>` into the builder
452+
#[inline]
450453
pub fn append_option(&mut self, v: Option<bool>) -> Result<()> {
451454
match v {
452455
None => self.append_null()?,
@@ -456,13 +459,15 @@ impl BooleanBuilder {
456459
}
457460

458461
/// Appends a slice of type `T` into the builder
462+
#[inline]
459463
pub fn append_slice(&mut self, v: &[bool]) -> Result<()> {
460464
self.bitmap_builder.append_n(v.len(), true);
461465
self.values_builder.append_slice(v);
462466
Ok(())
463467
}
464468

465469
/// Appends values from a slice of type `T` and a validity boolean slice
470+
#[inline]
466471
pub fn append_values(&mut self, values: &[bool], is_valid: &[bool]) -> Result<()> {
467472
if values.len() != is_valid.len() {
468473
return Err(ArrowError::InvalidArgumentError(
@@ -578,6 +583,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
578583
}
579584

580585
/// Appends a value of type `T` into the builder
586+
#[inline]
581587
pub fn append_value(&mut self, v: T::Native) -> Result<()> {
582588
if let Some(b) = self.bitmap_builder.as_mut() {
583589
b.append(true);
@@ -587,6 +593,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
587593
}
588594

589595
/// Appends a null slot into the builder
596+
#[inline]
590597
pub fn append_null(&mut self) -> Result<()> {
591598
self.materialize_bitmap_builder();
592599
self.bitmap_builder.as_mut().unwrap().append(false);
@@ -595,6 +602,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
595602
}
596603

597604
/// Appends an `Option<T>` into the builder
605+
#[inline]
598606
pub fn append_option(&mut self, v: Option<T::Native>) -> Result<()> {
599607
match v {
600608
None => self.append_null()?,
@@ -604,6 +612,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
604612
}
605613

606614
/// Appends a slice of type `T` into the builder
615+
#[inline]
607616
pub fn append_slice(&mut self, v: &[T::Native]) -> Result<()> {
608617
if let Some(b) = self.bitmap_builder.as_mut() {
609618
b.append_n(v.len(), true);
@@ -613,6 +622,7 @@ impl<T: ArrowPrimitiveType> PrimitiveBuilder<T> {
613622
}
614623

615624
/// Appends values from a slice of type `T` and a validity boolean slice
625+
#[inline]
616626
pub fn append_values(
617627
&mut self,
618628
values: &[T::Native],
@@ -766,6 +776,7 @@ where
766776
}
767777

768778
/// Finish the current variable-length list array slot
779+
#[inline]
769780
pub fn append(&mut self, is_valid: bool) -> Result<()> {
770781
self.offsets_builder
771782
.append(OffsetSize::from_usize(self.values_builder.len()).unwrap());
@@ -897,6 +908,7 @@ where
897908
}
898909

899910
/// Finish the current variable-length list array slot
911+
#[inline]
900912
pub fn append(&mut self, is_valid: bool) -> Result<()> {
901913
self.bitmap_builder.append(is_valid);
902914
self.len += 1;
@@ -1115,6 +1127,7 @@ impl<OffsetSize: BinaryOffsetSizeTrait> GenericBinaryBuilder<OffsetSize> {
11151127
///
11161128
/// Note, when appending individual byte values you must call `append` to delimit each
11171129
/// distinct list value.
1130+
#[inline]
11181131
pub fn append_byte(&mut self, value: u8) -> Result<()> {
11191132
self.builder.values().append_value(value)?;
11201133
Ok(())
@@ -1124,18 +1137,21 @@ impl<OffsetSize: BinaryOffsetSizeTrait> GenericBinaryBuilder<OffsetSize> {
11241137
///
11251138
/// Automatically calls the `append` method to delimit the slice appended in as a
11261139
/// distinct array element.
1140+
#[inline]
11271141
pub fn append_value(&mut self, value: impl AsRef<[u8]>) -> Result<()> {
11281142
self.builder.values().append_slice(value.as_ref())?;
11291143
self.builder.append(true)?;
11301144
Ok(())
11311145
}
11321146

11331147
/// Finish the current variable-length list array slot.
1148+
#[inline]
11341149
pub fn append(&mut self, is_valid: bool) -> Result<()> {
11351150
self.builder.append(is_valid)
11361151
}
11371152

11381153
/// Append a null value to the array.
1154+
#[inline]
11391155
pub fn append_null(&mut self) -> Result<()> {
11401156
self.append(false)
11411157
}
@@ -1170,6 +1186,7 @@ impl<OffsetSize: StringOffsetSizeTrait> GenericStringBuilder<OffsetSize> {
11701186
///
11711187
/// Automatically calls the `append` method to delimit the string appended in as a
11721188
/// distinct array element.
1189+
#[inline]
11731190
pub fn append_value(&mut self, value: impl AsRef<str>) -> Result<()> {
11741191
self.builder
11751192
.values()
@@ -1179,11 +1196,13 @@ impl<OffsetSize: StringOffsetSizeTrait> GenericStringBuilder<OffsetSize> {
11791196
}
11801197

11811198
/// Finish the current variable-length list array slot.
1199+
#[inline]
11821200
pub fn append(&mut self, is_valid: bool) -> Result<()> {
11831201
self.builder.append(is_valid)
11841202
}
11851203

11861204
/// Append a null value to the array.
1205+
#[inline]
11871206
pub fn append_null(&mut self) -> Result<()> {
11881207
self.append(false)
11891208
}
@@ -1208,6 +1227,7 @@ impl FixedSizeBinaryBuilder {
12081227
///
12091228
/// Automatically calls the `append` method to delimit the slice appended in as a
12101229
/// distinct array element.
1230+
#[inline]
12111231
pub fn append_value(&mut self, value: impl AsRef<[u8]>) -> Result<()> {
12121232
if self.builder.value_length() != value.as_ref().len() as i32 {
12131233
return Err(ArrowError::InvalidArgumentError(
@@ -1219,6 +1239,7 @@ impl FixedSizeBinaryBuilder {
12191239
}
12201240

12211241
/// Append a null value to the array.
1242+
#[inline]
12221243
pub fn append_null(&mut self) -> Result<()> {
12231244
let length: usize = self.builder.value_length() as usize;
12241245
self.builder.values().append_slice(&vec![0u8; length][..])?;
@@ -1248,6 +1269,7 @@ impl DecimalBuilder {
12481269
///
12491270
/// Automatically calls the `append` method to delimit the slice appended in as a
12501271
/// distinct array element.
1272+
#[inline]
12511273
pub fn append_value(&mut self, value: i128) -> Result<()> {
12521274
let value_as_bytes = Self::from_i128_to_fixed_size_bytes(
12531275
value,
@@ -1276,6 +1298,7 @@ impl DecimalBuilder {
12761298
}
12771299

12781300
/// Append a null value to the array.
1301+
#[inline]
12791302
pub fn append_null(&mut self) -> Result<()> {
12801303
let length: usize = self.builder.value_length() as usize;
12811304
self.builder.values().append_slice(&vec![0u8; length][..])?;
@@ -1465,13 +1488,15 @@ impl StructBuilder {
14651488

14661489
/// Appends an element (either null or non-null) to the struct. The actual elements
14671490
/// should be appended for each child sub-array in a consistent way.
1491+
#[inline]
14681492
pub fn append(&mut self, is_valid: bool) -> Result<()> {
14691493
self.bitmap_builder.append(is_valid);
14701494
self.len += 1;
14711495
Ok(())
14721496
}
14731497

14741498
/// Appends a null element to the struct.
1499+
#[inline]
14751500
pub fn append_null(&mut self) -> Result<()> {
14761501
self.append(false)
14771502
}
@@ -1649,6 +1674,7 @@ impl UnionBuilder {
16491674
}
16501675

16511676
/// Appends a null to this builder.
1677+
#[inline]
16521678
pub fn append_null(&mut self) -> Result<()> {
16531679
if self.bitmap_builder.is_none() {
16541680
let mut builder = BooleanBufferBuilder::new(self.len + 1);
@@ -1675,6 +1701,7 @@ impl UnionBuilder {
16751701
}
16761702

16771703
/// Appends a value to this builder.
1704+
#[inline]
16781705
pub fn append<T: ArrowPrimitiveType>(
16791706
&mut self,
16801707
type_name: &str,
@@ -1844,6 +1871,7 @@ where
18441871
/// Append a primitive value to the array. Return an existing index
18451872
/// if already present in the values array or a new index if the
18461873
/// value is appended to the values array.
1874+
#[inline]
18471875
pub fn append(&mut self, value: V::Native) -> Result<K::Native> {
18481876
if let Some(&key) = self.map.get(value.to_byte_slice()) {
18491877
// Append existing value.
@@ -1860,6 +1888,7 @@ where
18601888
}
18611889
}
18621890

1891+
#[inline]
18631892
pub fn append_null(&mut self) -> Result<()> {
18641893
self.keys_builder.append_null()
18651894
}
@@ -2047,6 +2076,7 @@ where
20472076
}
20482077
}
20492078

2079+
#[inline]
20502080
pub fn append_null(&mut self) -> Result<()> {
20512081
self.keys_builder.append_null()
20522082
}

0 commit comments

Comments
 (0)