Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions encodings/fsst/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use vortex_error::VortexResult;

use crate::FSST;
use crate::FSSTArrayExt;
use crate::decompressor::OptimizedDecompressor;

pub(super) fn canonicalize_fsst(
array: ArrayView<'_, FSST>,
Expand Down Expand Up @@ -59,29 +60,27 @@ pub(crate) fn fsst_decode_views(
.clone()
.execute::<PrimitiveArray>(ctx)?;

#[expect(clippy::cast_possible_truncation)]
let total_size: usize = match_each_integer_ptype!(uncompressed_lens_array.ptype(), |P| {
uncompressed_lens_array
.as_slice::<P>()
.iter()
.map(|x| *x as usize)
.sum()
});

// Bulk-decompress the entire array.
let decompressor = fsst_array.decompressor();
let mut uncompressed_bytes = ByteBufferMut::with_capacity(total_size + 7);
let len =
decompressor.decompress_into(bytes.as_slice(), uncompressed_bytes.spare_capacity_mut());
unsafe { uncompressed_bytes.set_len(len) };

// Directly create the binary views.
// Single dispatch: sum lengths, decompress, and build views in one match arm.
match_each_integer_ptype!(uncompressed_lens_array.ptype(), |P| {
let lens = uncompressed_lens_array.as_slice::<P>();
#[allow(clippy::cast_possible_truncation)]
let total_size: usize = lens.iter().map(|x| *x as usize).sum();

// Bulk-decompress the entire array.
let decompressor = OptimizedDecompressor::new(
fsst_array.symbols().as_slice(),
fsst_array.symbol_lengths().as_slice(),
);
let mut uncompressed_bytes = ByteBufferMut::with_capacity(total_size + 7);
let len =
decompressor.decompress_into(bytes.as_slice(), uncompressed_bytes.spare_capacity_mut());
unsafe { uncompressed_bytes.set_len(len) };

Ok(build_views(
start_buf_index,
MAX_BUFFER_LEN,
uncompressed_bytes,
uncompressed_lens_array.as_slice::<P>(),
lens,
))
})
}
Expand Down
Loading
Loading