Skip to content

Commit

Permalink
Optimize allocation of collections in to_scylla_value
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Aug 14, 2024
1 parent 29edc29 commit 8e23344
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/scripting/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ fn to_scylla_value(v: &Value, typ: &ColumnType) -> Result<CqlValue, CassError> {
},
(Value::Vec(v), ColumnType::List(elt)) => {
let v = v.borrow_ref().unwrap();
let elements = v
.as_ref()
.iter()
.map(|v| to_scylla_value(v, elt))
.try_collect()?;
let mut elements = Vec::with_capacity(v.len());
for elem in v.iter() {
let elem = to_scylla_value(elem, elt)?;
elements.push(elem);
}
Ok(CqlValue::List(elements))
}
(Value::Vec(v), ColumnType::Vector(elt, _dim)) => {
let v = v.borrow_ref().unwrap();
let elements = v
.as_ref()
.iter()
.map(|v| to_scylla_value(v, elt))
.try_collect()?;
let mut elements = Vec::with_capacity(v.len());
for elem in v.iter() {
let elem = to_scylla_value(elem, elt)?;
elements.push(elem);
}
Ok(CqlValue::Vector(elements))
}
(Value::Vec(v), ColumnType::Set(elt)) => {
let v = v.borrow_ref().unwrap();
let elements = v
.as_ref()
.iter()
.map(|v| to_scylla_value(v, elt))
.try_collect()?;
let mut elements = Vec::with_capacity(v.len());
for elem in v.iter() {
let elem = to_scylla_value(elem, elt)?;
elements.push(elem);
}
Ok(CqlValue::Set(elements))
}
(Value::Vec(v), ColumnType::Map(key_elt, value_elt)) => {
Expand Down

0 comments on commit 8e23344

Please sign in to comment.