Skip to content

Commit dbec716

Browse files
authored
chore: #[inline] fns vortex-dtype (#4486)
Annotates small functions in vortex-dtype with `#[inline]` that could benefit from cross crate inlining. Signed-off-by: Alexander Droste <[email protected]>
1 parent 1af178b commit dbec716

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

vortex-dtype/src/dtype.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ impl DType {
105105
pub const BYTES: Self = Primitive(PType::U8, Nullability::NonNullable);
106106

107107
/// Get the nullability of the `DType`.
108+
#[inline]
108109
pub fn nullability(&self) -> Nullability {
109110
self.is_nullable().into()
110111
}
111112

112113
/// Check if the `DType` is [`Nullability::Nullable`].
114+
#[inline]
113115
pub fn is_nullable(&self) -> bool {
114116
match self {
115117
Null => true,

vortex-dtype/src/nullability.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl Nullability {
2929
impl BitOr for Nullability {
3030
type Output = Nullability;
3131

32+
#[inline]
3233
fn bitor(self, rhs: Self) -> Self::Output {
3334
match (self, rhs) {
3435
(Self::NonNullable, Self::NonNullable) => Self::NonNullable,
@@ -38,6 +39,7 @@ impl BitOr for Nullability {
3839
}
3940

4041
impl From<bool> for Nullability {
42+
#[inline]
4143
fn from(value: bool) -> Self {
4244
if value {
4345
Self::Nullable
@@ -48,6 +50,7 @@ impl From<bool> for Nullability {
4850
}
4951

5052
impl From<Nullability> for bool {
53+
#[inline]
5154
fn from(value: Nullability) -> Self {
5255
match value {
5356
Nullability::NonNullable => false,

vortex-dtype/src/ptype.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,38 +598,45 @@ macro_rules! match_each_native_simd_ptype {
598598

599599
impl PType {
600600
/// Returns `true` iff this PType is an unsigned integer type
601+
#[inline]
601602
pub const fn is_unsigned_int(self) -> bool {
602603
matches!(self, Self::U8 | Self::U16 | Self::U32 | Self::U64)
603604
}
604605

605606
/// Returns `true` iff this PType is a signed integer type
607+
#[inline]
606608
pub const fn is_signed_int(self) -> bool {
607609
matches!(self, Self::I8 | Self::I16 | Self::I32 | Self::I64)
608610
}
609611

610612
/// Returns `true` iff this PType is an integer type
611613
/// Equivalent to `self.is_unsigned_int() || self.is_signed_int()`
614+
#[inline]
612615
pub const fn is_int(self) -> bool {
613616
self.is_unsigned_int() || self.is_signed_int()
614617
}
615618

616619
/// Returns `true` iff this PType is a floating point type
620+
#[inline]
617621
pub const fn is_float(self) -> bool {
618622
matches!(self, Self::F16 | Self::F32 | Self::F64)
619623
}
620624

621625
/// Returns the number of bytes in this PType
626+
#[inline]
622627
pub const fn byte_width(&self) -> usize {
623628
match_each_native_ptype!(self, |T| { size_of::<T>() })
624629
}
625630

626631
/// Returns the number of bits in this PType
632+
#[inline]
627633
pub const fn bit_width(&self) -> usize {
628634
self.byte_width() * 8
629635
}
630636

631637
/// Returns the maximum value of this PType if it is an integer type
632638
/// Returns `u64::MAX` if the value is too large to fit in a `u64`
639+
#[inline]
633640
pub fn max_value_as_u64(&self) -> u64 {
634641
match_each_native_ptype!(self, |T| {
635642
<T as UpperBounded>::max_value()
@@ -639,6 +646,7 @@ impl PType {
639646
}
640647

641648
/// Returns the PType that corresponds to the signed version of this PType
649+
#[inline]
642650
pub const fn to_signed(self) -> Self {
643651
match self {
644652
Self::U8 => Self::I8,
@@ -653,6 +661,7 @@ impl PType {
653661

654662
/// Returns the PType that corresponds to the unsigned version of this PType
655663
/// For floating point types, this will simply return `self`
664+
#[inline]
656665
pub const fn to_unsigned(self) -> Self {
657666
match self {
658667
Self::I8 => Self::U8,

vortex-mask/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl MaskValues {
180180

181181
/// Constructs a slices vector from one of the other representations.
182182
#[allow(clippy::cast_possible_truncation)]
183+
#[inline]
183184
pub fn slices(&self) -> &[(usize, usize)] {
184185
self.slices.get_or_init(|| {
185186
if self.true_count == self.len() {
@@ -191,6 +192,7 @@ impl MaskValues {
191192
}
192193

193194
/// Return an iterator over either indices or slices of the mask based on a density threshold.
195+
#[inline]
194196
pub fn threshold_iter(&self, threshold: f64) -> MaskIter<'_> {
195197
if self.density >= threshold {
196198
MaskIter::Slices(self.slices())

0 commit comments

Comments
 (0)