Skip to content

Commit b1517fe

Browse files
committed
frame/result: inline deser_table_spec_for_col_spec
After equality checks were removed between table specs in consecutive column specs, deser_table_spec_for_col_spec has now trivial logic that is concise enough to be inlined into deser_col_specs_generic.
1 parent 39327a3 commit b1517fe

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

scylla-cql/src/frame/response/result.rs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -977,55 +977,22 @@ fn mk_col_spec_parse_error(
977977
}
978978
}
979979

980-
/// Deserializes table spec of a column spec in the borrowed form.
981-
///
982-
/// To avoid needless allocations, it is advised to pass `known_table_spec`
983-
/// in the borrowed form, so that cloning it is cheap.
984-
fn deser_table_spec_for_col_spec<'frame>(
985-
buf: &'_ mut &'frame [u8],
986-
global_table_spec_provided: bool,
987-
known_table_spec: &'_ mut Option<TableSpec<'frame>>,
988-
col_idx: usize,
989-
) -> StdResult<TableSpec<'frame>, ColumnSpecParseError> {
990-
let table_spec = match known_table_spec {
991-
// If global table spec was provided, we simply clone it to each column spec.
992-
Some(ref known_spec) if global_table_spec_provided => known_spec.clone(),
993-
994-
// Else, we deserialize the table spec for a column.
995-
Some(_) | None => {
996-
let table_spec =
997-
deser_table_spec(buf).map_err(|err| mk_col_spec_parse_error(col_idx, err))?;
998-
999-
if known_table_spec.is_none() {
1000-
// Once we have read the first column spec, we save its table spec.
1001-
*known_table_spec = Some(table_spec.clone());
1002-
}
1003-
1004-
table_spec
1005-
}
1006-
};
1007-
1008-
Ok(table_spec)
1009-
}
1010-
1011980
fn deser_col_specs_generic<'frame, 'result>(
1012981
buf: &mut &'frame [u8],
1013982
global_table_spec: Option<TableSpec<'frame>>,
1014983
col_count: usize,
1015984
make_col_spec: fn(&'frame str, ColumnType<'result>, TableSpec<'frame>) -> ColumnSpec<'result>,
1016985
deser_type: fn(&mut &'frame [u8]) -> StdResult<ColumnType<'result>, CqlTypeParseError>,
1017986
) -> StdResult<Vec<ColumnSpec<'result>>, ColumnSpecParseError> {
1018-
let global_table_spec_provided = global_table_spec.is_some();
1019-
let mut known_table_spec = global_table_spec;
1020-
1021987
let mut col_specs = Vec::with_capacity(col_count);
1022988
for col_idx in 0..col_count {
1023-
let table_spec = deser_table_spec_for_col_spec(
1024-
buf,
1025-
global_table_spec_provided,
1026-
&mut known_table_spec,
1027-
col_idx,
1028-
)?;
989+
let table_spec = match global_table_spec {
990+
// If global table spec was provided, we simply clone it to each column spec.
991+
Some(ref known_spec) => known_spec.clone(),
992+
993+
// Else, we deserialize the table spec for a column.
994+
None => deser_table_spec(buf).map_err(|err| mk_col_spec_parse_error(col_idx, err))?,
995+
};
1029996

1030997
let name = types::read_string(buf).map_err(|err| mk_col_spec_parse_error(col_idx, err))?;
1031998
let typ = deser_type(buf).map_err(|err| mk_col_spec_parse_error(col_idx, err))?;

0 commit comments

Comments
 (0)