Skip to content

Commit

Permalink
perf: improve deserialization of value encoding for struct/list (#5897)
Browse files Browse the repository at this point in the history
improve value encoding for struct/list

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
waruto210 and mergify[bot] authored Oct 18, 2022
1 parent f4e4475 commit 52e0ca4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/common/src/util/value_encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ fn deserialize_value(ty: &DataType, data: &mut impl Buf) -> Result<Datum> {
}

fn deserialize_struct(struct_def: &StructType, data: &mut impl Buf) -> Result<ScalarImpl> {
let field_values = struct_def
.fields
.iter()
.map(|field_type| inner_deserialize_datum(data, field_type))
.collect::<Result<Vec<Datum>>>()?;
let num_fields = struct_def.fields.len();
let mut field_values = Vec::with_capacity(num_fields);
for field_type in &struct_def.fields {
field_values.push(inner_deserialize_datum(data, field_type)?);
}

Ok(ScalarImpl::Struct(StructValue::new(field_values)))
}

fn deserialize_list(item_type: &DataType, data: &mut impl Buf) -> Result<ScalarImpl> {
let len = data.get_u32_le();
let values = (0..len)
.map(|_| inner_deserialize_datum(data, item_type))
.collect::<Result<Vec<Datum>>>()?;

let mut values = Vec::with_capacity(len as usize);
for _ in 0..len {
values.push(inner_deserialize_datum(data, item_type)?);
}
Ok(ScalarImpl::List(ListValue::new(values)))
}

Expand Down

0 comments on commit 52e0ca4

Please sign in to comment.