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
25 changes: 19 additions & 6 deletions engine/src/functions/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@ impl ConcatFunction {
}
}

fn concat_array<'a>(mut accumulator: Array<'a>, args: FunctionArgs<'_, 'a>) -> Array<'a> {
fn concat_array<'a>(accumulator: Array<'a>, args: FunctionArgs<'_, 'a>) -> Array<'a> {
let mut args = args.flat_map(|arg| arg.ok());
let Some(first) = args.next() else {
return accumulator;
};
let val_type = accumulator.value_type();
let mut vec = accumulator.into_vec();
match first {
LhsValue::Array(value) => {
vec.extend(value);
}
_ => unreachable!(),
}
for arg in args {
match arg {
Ok(LhsValue::Array(value)) => accumulator.try_extend(value).unwrap(),
Err(Type::Array(_)) => (),
_ => (),
};
LhsValue::Array(value) => {
vec.extend(value);
}
_ => unreachable!(),
}
}
accumulator
Array::try_from_vec(val_type, vec).unwrap()
}

fn concat_bytes<'a>(mut accumulator: Cow<'a, [u8]>, args: FunctionArgs<'_, 'a>) -> Cow<'a, [u8]> {
Expand Down
25 changes: 6 additions & 19 deletions engine/src/lhs_types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,13 @@ impl<'a> Array<'a> {
})
}

/// Try extending the array with elements provided by the specified iterator.
pub fn try_extend<V, I>(&mut self, iter: I) -> Result<(), TypeMismatchError>
where
V: Into<LhsValue<'a>>,
I: IntoIterator<Item = V>,
{
let value_type = self.value_type();
let vec = self.data.as_vec();
for elem in iter {
let elem = elem.into();
let elem_type = elem.get_type();
if value_type != elem_type {
return Err(TypeMismatchError {
expected: value_type.into(),
actual: elem_type,
});
};
vec.push(elem);
/// Converts the array into a vector.
#[inline]
pub fn into_vec(self) -> Vec<LhsValue<'a>> {
match self.data {
InnerArray::Owned(vec) => vec,
InnerArray::Borrowed(slice) => slice.iter().map(LhsValue::as_ref).collect(),
}
Ok(())
}
}

Expand Down