Skip to content
Merged
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
5 changes: 5 additions & 0 deletions vortex-array/src/array/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,19 @@ impl ArrayRef {
}

/// Does the array match the given matcher.
#[inline]
pub fn is<M: Matcher>(&self) -> bool {
M::matches(self)
}

/// Returns the array downcast by the given matcher.
#[inline]
pub fn as_<M: Matcher>(&self) -> M::Match<'_> {
self.as_opt::<M>().vortex_expect("Failed to downcast")
}

/// Returns the array downcast by the given matcher.
#[inline]
pub fn as_opt<M: Matcher>(&self) -> Option<M::Match<'_>> {
M::try_match(self)
}
Expand Down Expand Up @@ -738,10 +741,12 @@ impl IntoArray for ArrayRef {
impl<V: VTable> Matcher for V {
type Match<'a> = ArrayView<'a, V>;

#[inline]
fn matches(array: &ArrayRef) -> bool {
array.0.data.as_any().is::<ArrayData<V>>()
}

#[inline]
fn try_match(array: &'_ ArrayRef) -> Option<ArrayView<'_, V>> {
let inner = array.0.data.as_any().downcast_ref::<ArrayData<V>>()?;
// # Safety checked by `downcast_ref`.
Expand Down
1 change: 1 addition & 0 deletions vortex-array/src/arrays/varbinview/compute/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ fn push_range(
}
}

#[inline]
fn push_view(
view: BinaryView,
buffer_lookup: &[u32],
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl BufferHandle {
}

/// Downcast this handle as a handle to a host-resident buffer, or `None`.
#[inline]
pub fn as_host_opt(&self) -> Option<&ByteBuffer> {
match &self.0 {
Inner::Host(buffer) => Some(buffer),
Expand All @@ -266,6 +267,7 @@ impl BufferHandle {

/// A version of [`as_host_opt`][Self::as_host_opt] that panics if the allocation is
/// not a host allocation.
#[inline]
pub fn as_host(&self) -> &ByteBuffer {
self.as_host_opt().vortex_expect("expected host buffer")
}
Expand Down
3 changes: 3 additions & 0 deletions vortex-array/src/builders/varbinview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ impl ArrayBuilder for VarBinViewBuilder {
}

impl VarBinViewBuilder {
#[inline]
fn push_view(
&mut self,
view: BinaryView,
Expand Down Expand Up @@ -758,6 +759,7 @@ enum PrecomputedViewAdjustment {
}

impl PrecomputedViewAdjustment {
#[inline]
fn adjust_view(&self, view: &BinaryView) -> BinaryView {
if view.is_inlined() {
return *view;
Expand Down Expand Up @@ -815,6 +817,7 @@ struct RewritingViewAdjustment {
impl RewritingViewAdjustment {
/// Can return None if this view can't be adjusted, because there is no precomputed lookup
/// for the current buffer.
#[inline]
fn adjust_view(&self, view: &BinaryView) -> Option<BinaryView> {
if view.is_inlined() {
return Some(*view);
Expand Down
2 changes: 2 additions & 0 deletions vortex-array/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ pub struct AnyCanonical;
impl Matcher for AnyCanonical {
type Match<'a> = CanonicalView<'a>;

#[inline]
fn matches(array: &ArrayRef) -> bool {
array.is::<Null>()
|| array.is::<Bool>()
Expand All @@ -1085,6 +1086,7 @@ impl Matcher for AnyCanonical {
|| array.is::<Extension>()
}

#[inline]
fn try_match(array: &ArrayRef) -> Option<Self::Match<'_>> {
if let Some(a) = array.as_opt::<Null>() {
Some(CanonicalView::Null(a))
Expand Down
1 change: 1 addition & 0 deletions vortex-array/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub trait Matcher {
type Match<'a>;

/// Check if the given array matches this matcher type
#[inline]
fn matches(array: &ArrayRef) -> bool {
Self::try_match(array).is_some()
}
Expand Down
7 changes: 7 additions & 0 deletions vortex-array/src/search_sorted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ pub trait IndexOrd<V> {
/// For example, if self\[idx\] > elem, return Some(Greater).
fn index_cmp(&self, idx: usize, elem: &V) -> VortexResult<Option<Ordering>>;

#[inline]
fn index_lt(&self, idx: usize, elem: &V) -> VortexResult<bool> {
Ok(matches!(self.index_cmp(idx, elem)?, Some(Less)))
}

#[inline]
fn index_le(&self, idx: usize, elem: &V) -> VortexResult<bool> {
Ok(matches!(self.index_cmp(idx, elem)?, Some(Less | Equal)))
}
Expand All @@ -132,6 +134,7 @@ pub trait IndexOrd<V> {
/// |left |array\[i-1\] < value <= array\[i\]|
/// |right|array\[i-1\] <= value < array\[i\]|
pub trait SearchSorted<T> {
#[inline]
fn search_sorted(&self, value: &T, side: SearchSortedSide) -> VortexResult<SearchResult>
where
Self: IndexOrd<T>,
Expand Down Expand Up @@ -180,6 +183,7 @@ impl<S, T> SearchSorted<T> for S
where
S: IndexOrd<T> + ?Sized,
{
#[inline]
fn search_sorted_by<
F: FnMut(usize) -> VortexResult<Ordering>,
N: FnMut(usize) -> VortexResult<Ordering>,
Expand Down Expand Up @@ -210,6 +214,7 @@ where
}

// Code adapted from Rust standard library slice::binary_search_by
#[inline]
fn search_sorted_side_idx<F: FnMut(usize) -> VortexResult<Ordering>>(
mut find: F,
from: usize,
Expand Down Expand Up @@ -276,11 +281,13 @@ impl IndexOrd<Scalar> for ArrayRef {
}

impl<T: PartialOrd> IndexOrd<T> for [T] {
#[inline]
fn index_cmp(&self, idx: usize, elem: &T) -> VortexResult<Option<Ordering>> {
// SAFETY: Used in search_sorted_by same as the standard library. The search_sorted ensures idx is in bounds
Ok(unsafe { self.get_unchecked(idx) }.partial_cmp(elem))
}

#[inline]
fn index_len(&self) -> usize {
self.len()
}
Expand Down
1 change: 1 addition & 0 deletions vortex-buffer/src/bit/buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl From<Vec<bool>> for BitBufferMut {
}

impl FromIterator<bool> for BitBufferMut {
#[inline]
fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self {
let mut iter = iter.into_iter();

Expand Down
Loading