Skip to content

Commit

Permalink
Use then vs then_some for values that have to be lazy (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Aug 12, 2024
1 parent 7d02111 commit 1b22286
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions encodings/fastlanes/src/bitpacking/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ pub fn bitpack_encode(array: PrimitiveArray, bit_width: usize) -> VortexResult<B
}

let packed = bitpack(&array, bit_width)?;
let patches =
(num_exceptions > 0).then_some(bitpack_patches(&array, bit_width, num_exceptions));
let patches = (num_exceptions > 0).then(|| bitpack_patches(&array, bit_width, num_exceptions));

BitPackedArray::try_new(packed, array.validity(), patches, bit_width, array.len())
}
Expand Down
12 changes: 7 additions & 5 deletions encodings/fastlanes/src/bitpacking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ impl BitPackedArray {
#[inline]
pub fn patches(&self) -> Option<Array> {
(self.metadata().patches_len > 0)
.then_some(self.array().child(
1,
&self.dtype().with_nullability(Nullability::Nullable),
self.metadata().patches_len,
))
.then(|| {
self.array().child(
1,
&self.dtype().with_nullability(Nullability::Nullable),
self.metadata().patches_len,
)
})
.flatten()
}

Expand Down
8 changes: 1 addition & 7 deletions vortex-array/src/array/bool/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ impl ArrayAccessor<bool> for BoolArray {
Validity::Array(valid) => {
let valids = valid.into_bool()?.boolean_buffer();
let mut iter = valids.iter().zip(bools.iter()).map(|(is_valid, value)| {
is_valid.then_some({
if value {
&TRUE
} else {
&FALSE
}
})
is_valid.then_some(if value { &TRUE } else { &FALSE })
});

Ok(f(&mut iter))
Expand Down
12 changes: 8 additions & 4 deletions vortex-sampling-compressor/src/compressors/bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ impl EncodingCompressor for BitPackedCompressor {

let validity = ctx.compress_validity(parray.validity())?;
let packed = bitpack(&parray, bit_width)?;
let patches = (num_exceptions > 0).then_some(ctx.auxiliary("patches").compress(
&bitpack_patches(&parray, bit_width, num_exceptions),
like.as_ref().and_then(|l| l.child(0)),
)?);
let patches = (num_exceptions > 0)
.then(|| {
ctx.auxiliary("patches").compress(
&bitpack_patches(&parray, bit_width, num_exceptions),
like.as_ref().and_then(|l| l.child(0)),
)
})
.transpose()?;

Ok(CompressedArray::new(
BitPackedArray::try_new(
Expand Down

0 comments on commit 1b22286

Please sign in to comment.