Skip to content

Commit 3c5e540

Browse files
committed
replace match statements
Signed-off-by: Connor Tsui <[email protected]>
1 parent db61cec commit 3c5e540

File tree

3 files changed

+20
-57
lines changed

3 files changed

+20
-57
lines changed

vortex-vector/src/macros.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,10 @@ macro_rules! __match_vector_pair_arms {
230230
/// let new_bool_mut = extend_vector_owned(mut_vec, vec);
231231
/// assert_eq!(new_bool_mut.len(), 5);
232232
/// ```
233-
#[rustfmt::skip]
234-
#[macro_export]
233+
#[macro_export] // DO NOT ADD `#[rustfmt::skip]`!!! https://github.com/rust-lang/rust/pull/52234#issuecomment-903419099
235234
macro_rules! match_vector_pair {
236-
($left:expr, $right:expr, | $a:ident: Vector, $b:ident: Vector | $body:expr) => {{
237-
$crate::__match_vector_pair_arms!($left, $right, Vector, Vector, $a, $b, $body)
238-
}};
239-
($left:expr, $right:expr, | $a:ident: Vector, $b:ident: VectorMut | $body:expr) => {{
240-
$crate::__match_vector_pair_arms!($left, $right, Vector, VectorMut, $a, $b, $body)
241-
}};
242-
($left:expr, $right:expr, | $a:ident: VectorMut, $b:ident: Vector | $body:expr) => {{
243-
$crate::__match_vector_pair_arms!($left, $right, VectorMut, Vector, $a, $b, $body)
244-
}};
245-
($left:expr, $right:expr, | $a:ident: VectorMut, $b:ident: VectorMut | $body:expr) => {{
246-
$crate::__match_vector_pair_arms!($left, $right, VectorMut, VectorMut, $a, $b, $body)
247-
}};
235+
($left:expr, $right:expr, | $a:ident : Vector, $b:ident : Vector | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, Vector, Vector, $a, $b, $body) }};
236+
($left:expr, $right:expr, | $a:ident : Vector, $b:ident : VectorMut | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, Vector, VectorMut, $a, $b, $body) }};
237+
($left:expr, $right:expr, | $a:ident : VectorMut, $b:ident : Vector | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, VectorMut, Vector, $a, $b, $body) }};
238+
($left:expr, $right:expr, | $a:ident : VectorMut, $b:ident : VectorMut | $body:expr) => {{ $crate::__match_vector_pair_arms!($left, $right, VectorMut, VectorMut, $a, $b, $body) }};
248239
}

vortex-vector/src/struct_/vector_mut.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
use std::sync::Arc;
77

8-
use vortex_error::{VortexExpect, VortexResult, vortex_ensure, vortex_panic};
8+
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
99
use vortex_mask::MaskMut;
1010

11-
use crate::{StructVector, Vector, VectorMut, VectorMutOps, VectorOps};
11+
use crate::{StructVector, Vector, VectorMut, VectorMutOps, VectorOps, match_vector_pair};
1212

1313
/// A mutable vector of struct values (values with named fields).
1414
///
@@ -239,17 +239,9 @@ impl VectorMutOps for StructVectorMut {
239239
// Extend each field vector.
240240
let pairs = self.fields.iter_mut().zip(other.fields().as_ref());
241241
for (self_mut_vector, other_vec) in pairs {
242-
match (self_mut_vector, other_vec) {
243-
(VectorMut::Null(a), Vector::Null(b)) => a.extend_from_vector(b),
244-
(VectorMut::Bool(a), Vector::Bool(b)) => a.extend_from_vector(b),
245-
(VectorMut::Primitive(a), Vector::Primitive(b)) => a.extend_from_vector(b),
246-
(VectorMut::String(a), Vector::String(b)) => a.extend_from_vector(b),
247-
(VectorMut::Binary(a), Vector::Binary(b)) => a.extend_from_vector(b),
248-
(VectorMut::Struct(a), Vector::Struct(b)) => a.extend_from_vector(b),
249-
_ => {
250-
vortex_panic!("Mismatched field types in `StructVectorMut::extend_from_vector`")
251-
}
252-
}
242+
match_vector_pair!(self_mut_vector, other_vec, |a: VectorMut, b: Vector| {
243+
a.extend_from_vector(b)
244+
})
253245
}
254246

255247
// Extend the validity mask.
@@ -322,17 +314,11 @@ impl VectorMutOps for StructVectorMut {
322314
// Unsplit each field vector.
323315
let pairs = self.fields.iter_mut().zip(other.fields);
324316
for (self_mut_vector, other_mut_vec) in pairs {
325-
match (self_mut_vector, other_mut_vec) {
326-
(VectorMut::Null(a), VectorMut::Null(b)) => a.unsplit(b),
327-
(VectorMut::Bool(a), VectorMut::Bool(b)) => a.unsplit(b),
328-
(VectorMut::Primitive(a), VectorMut::Primitive(b)) => a.unsplit(b),
329-
(VectorMut::String(a), VectorMut::String(b)) => a.unsplit(b),
330-
(VectorMut::Binary(a), VectorMut::Binary(b)) => a.unsplit(b),
331-
(VectorMut::Struct(a), VectorMut::Struct(b)) => a.unsplit(b),
332-
_ => {
333-
vortex_panic!("Mismatched field types in `StructVectorMut::unsplit`")
334-
}
335-
}
317+
match_vector_pair!(
318+
self_mut_vector,
319+
other_mut_vec,
320+
|a: VectorMut, b: VectorMut| a.unsplit(b)
321+
)
336322
}
337323

338324
self.validity.unsplit(other.validity);

vortex-vector/src/vector_mut.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use vortex_mask::MaskMut;
1313
use crate::varbin::{BinaryVectorMut, StringVectorMut};
1414
use crate::{
1515
BoolVectorMut, NullVectorMut, PrimitiveVectorMut, StructVectorMut, Vector, VectorMutOps,
16-
match_each_vector_mut,
16+
match_each_vector_mut, match_vector_pair,
1717
};
1818

1919
/// An enum over all kinds of mutable vectors, which represent fully decompressed (canonical) array
@@ -94,15 +94,9 @@ impl VectorMutOps for VectorMut {
9494
}
9595

9696
fn extend_from_vector(&mut self, other: &Self::Immutable) {
97-
match (self, other) {
98-
(VectorMut::Null(a), Vector::Null(b)) => a.extend_from_vector(b),
99-
(VectorMut::Bool(a), Vector::Bool(b)) => a.extend_from_vector(b),
100-
(VectorMut::Primitive(a), Vector::Primitive(b)) => a.extend_from_vector(b),
101-
(VectorMut::String(a), Vector::String(b)) => a.extend_from_vector(b),
102-
(VectorMut::Binary(a), Vector::Binary(b)) => a.extend_from_vector(b),
103-
(VectorMut::Struct(a), Vector::Struct(b)) => a.extend_from_vector(b),
104-
_ => vortex_panic!("Mismatched vector types"),
105-
}
97+
match_vector_pair!(self, other, |a: VectorMut, b: Vector| {
98+
a.extend_from_vector(b)
99+
})
106100
}
107101

108102
fn append_nulls(&mut self, n: usize) {
@@ -118,15 +112,7 @@ impl VectorMutOps for VectorMut {
118112
}
119113

120114
fn unsplit(&mut self, other: Self) {
121-
match (self, other) {
122-
(VectorMut::Null(a), VectorMut::Null(b)) => a.unsplit(b),
123-
(VectorMut::Bool(a), VectorMut::Bool(b)) => a.unsplit(b),
124-
(VectorMut::Primitive(a), VectorMut::Primitive(b)) => a.unsplit(b),
125-
(VectorMut::String(a), VectorMut::String(b)) => a.unsplit(b),
126-
(VectorMut::Binary(a), VectorMut::Binary(b)) => a.unsplit(b),
127-
(VectorMut::Struct(a), VectorMut::Struct(b)) => a.unsplit(b),
128-
_ => vortex_panic!("Mismatched vector types"),
129-
}
115+
match_vector_pair!(self, other, |a: VectorMut, b: VectorMut| a.unsplit(b))
130116
}
131117
}
132118

0 commit comments

Comments
 (0)