Skip to content

Commit 44f3660

Browse files
committed
allow make view inline
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 6b83bac commit 44f3660

1 file changed

Lines changed: 15 additions & 50 deletions

File tree

  • vortex-array/src/arrays/varbinview

vortex-array/src/arrays/varbinview/view.rs

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ pub struct Inlined {
4646
}
4747

4848
impl Inlined {
49-
/// Creates a new inlined representation from the provided value of constant size.
50-
fn new<const N: usize>(value: &[u8]) -> Self {
51-
debug_assert_eq!(value.len(), N);
49+
/// Creates a new inlined representation from the provided byte slice.
50+
///
51+
/// The slice length must be <= [`BinaryView::MAX_INLINED_SIZE`] (12).
52+
#[inline]
53+
fn from_slice(value: &[u8]) -> Self {
54+
debug_assert!(value.len() <= BinaryView::MAX_INLINED_SIZE);
5255
let mut inlined = Self {
53-
size: N.try_into().vortex_expect("inlined size must fit in u32"),
56+
size: value.len() as u32,
5457
data: [0u8; BinaryView::MAX_INLINED_SIZE],
5558
};
56-
inlined.data[..N].copy_from_slice(&value[..N]);
59+
inlined.data[..value.len()].copy_from_slice(value);
5760
inlined
5861
}
5962

@@ -105,52 +108,14 @@ impl BinaryView {
105108
///
106109
/// Depending on the length of the provided value either a new inlined
107110
/// or a reference view will be constructed.
108-
///
109-
/// Adapted from arrow-rs <https://github.com/apache/arrow-rs/blob/f4fde769ab6e1a9b75f890b7f8b47bc22800830b/arrow-array/src/builder/generic_bytes_view_builder.rs#L524>
110-
/// Explicitly enumerating inlined view produces code that avoids calling generic `ptr::copy_non_interleave` that's slower than explicit stores
111111
#[inline]
112112
pub fn make_view(value: &[u8], block: u32, offset: u32) -> Self {
113-
match value.len() {
114-
0 => Self {
115-
inlined: Inlined::new::<0>(value),
116-
},
117-
1 => Self {
118-
inlined: Inlined::new::<1>(value),
119-
},
120-
2 => Self {
121-
inlined: Inlined::new::<2>(value),
122-
},
123-
3 => Self {
124-
inlined: Inlined::new::<3>(value),
125-
},
126-
4 => Self {
127-
inlined: Inlined::new::<4>(value),
128-
},
129-
5 => Self {
130-
inlined: Inlined::new::<5>(value),
131-
},
132-
6 => Self {
133-
inlined: Inlined::new::<6>(value),
134-
},
135-
7 => Self {
136-
inlined: Inlined::new::<7>(value),
137-
},
138-
8 => Self {
139-
inlined: Inlined::new::<8>(value),
140-
},
141-
9 => Self {
142-
inlined: Inlined::new::<9>(value),
143-
},
144-
10 => Self {
145-
inlined: Inlined::new::<10>(value),
146-
},
147-
11 => Self {
148-
inlined: Inlined::new::<11>(value),
149-
},
150-
12 => Self {
151-
inlined: Inlined::new::<12>(value),
152-
},
153-
_ => Self {
113+
if value.len() <= Self::MAX_INLINED_SIZE {
114+
Self {
115+
inlined: Inlined::from_slice(value),
116+
}
117+
} else {
118+
Self {
154119
_ref: Ref {
155120
size: u32::try_from(value.len()).vortex_expect("value length must fit in u32"),
156121
prefix: value[0..4]
@@ -160,7 +125,7 @@ impl BinaryView {
160125
buffer_index: block,
161126
offset,
162127
},
163-
},
128+
}
164129
}
165130
}
166131

0 commit comments

Comments
 (0)