Skip to content

Commit 95faace

Browse files
utkarshgupta137marmeladema
authored andcommitted
Extract _impl functions
1 parent c644606 commit 95faace

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

engine/src/functions/all.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
};
55
use std::iter::once;
66

7-
#[inline]
87
fn all_impl<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
98
let arg = args.next().expect("expected 1 argument, got 0");
109
if args.next().is_some() {

engine/src/functions/any.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
};
55
use std::iter::once;
66

7-
#[inline]
87
fn any_impl<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
98
let arg = args.next().expect("expected 1 argument, got 0");
109
if args.next().is_some() {

engine/src/functions/concat.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl ConcatFunction {
2020
}
2121
}
2222

23+
#[inline]
2324
fn concat_array<'a>(accumulator: Array<'a>, args: FunctionArgs<'_, 'a>) -> Array<'a> {
2425
let mut args = args.flat_map(|arg| arg.ok());
2526
let Some(first) = args.next() else {
@@ -44,6 +45,7 @@ fn concat_array<'a>(accumulator: Array<'a>, args: FunctionArgs<'_, 'a>) -> Array
4445
Array::try_from_vec(val_type, vec).unwrap()
4546
}
4647

48+
#[inline]
4749
fn concat_bytes<'a>(mut accumulator: Vec<u8>, args: FunctionArgs<'_, 'a>) -> Bytes<'a> {
4850
for arg in args {
4951
match arg {
@@ -55,6 +57,25 @@ fn concat_bytes<'a>(mut accumulator: Vec<u8>, args: FunctionArgs<'_, 'a>) -> Byt
5557
accumulator.into()
5658
}
5759

60+
fn concat_impl<'a>(args: FunctionArgs<'_, 'a>) -> Option<LhsValue<'a>> {
61+
while let Some(arg) = args.next() {
62+
match arg {
63+
Ok(LhsValue::Array(array)) => {
64+
return Some(LhsValue::Array(concat_array(array, args)));
65+
}
66+
Ok(LhsValue::Bytes(bytes)) => {
67+
return Some(LhsValue::Bytes(concat_bytes(
68+
bytes.into_owned().into(),
69+
args,
70+
)));
71+
}
72+
Err(_) => (),
73+
_ => unreachable!(),
74+
}
75+
}
76+
None
77+
}
78+
5879
pub(crate) const EXPECTED_TYPES: [ExpectedType; 2] =
5980
[ExpectedType::Array, ExpectedType::Type(Type::Bytes)];
6081

@@ -96,24 +117,7 @@ impl FunctionDefinition for ConcatFunction {
96117
_: &mut dyn ExactSizeIterator<Item = FunctionParam<'_>>,
97118
_: Option<FunctionDefinitionContext>,
98119
) -> CompiledFunction {
99-
Box::new(|args| {
100-
while let Some(arg) = args.next() {
101-
match arg {
102-
Ok(LhsValue::Array(array)) => {
103-
return Some(LhsValue::Array(concat_array(array, args)));
104-
}
105-
Ok(LhsValue::Bytes(bytes)) => {
106-
return Some(LhsValue::Bytes(concat_bytes(
107-
bytes.into_owned().into(),
108-
args,
109-
)));
110-
}
111-
Err(_) => (),
112-
_ => unreachable!(),
113-
}
114-
}
115-
None
116-
})
120+
Box::new(concat_impl)
117121
}
118122
}
119123

@@ -133,7 +137,7 @@ mod tests {
133137
.into_iter();
134138
assert_eq!(
135139
Some(LhsValue::Bytes(Bytes::Borrowed(b"helloworld"))),
136-
CONCAT_FN.compile(&mut std::iter::empty(), None)(&mut args)
140+
concat_impl(&mut args)
137141
);
138142
}
139143

@@ -148,7 +152,7 @@ mod tests {
148152
.into_iter();
149153
assert_eq!(
150154
Some(LhsValue::Bytes(Bytes::Borrowed(b"helloworldhello2world2"))),
151-
CONCAT_FN.compile(&mut std::iter::empty(), None)(&mut args)
155+
concat_impl(&mut args)
152156
);
153157
}
154158

@@ -159,15 +163,15 @@ mod tests {
159163
let mut args = vec![Ok(arg1), Ok(arg2)].into_iter();
160164
assert_eq!(
161165
Some(LhsValue::Array(Array::from_iter([1, 2, 3, 4, 5, 6]))),
162-
CONCAT_FN.compile(&mut std::iter::empty(), None)(&mut args)
166+
concat_impl(&mut args)
163167
);
164168
}
165169

166170
#[test]
167171
#[should_panic]
168172
fn test_concat_function_bad_arg_type() {
169173
let mut args = vec![Ok(LhsValue::from(2))].into_iter();
170-
CONCAT_FN.compile(&mut std::iter::empty(), None)(&mut args);
174+
concat_impl(&mut args);
171175
}
172176

173177
#[test]

0 commit comments

Comments
 (0)