Skip to content

Commit 0368aea

Browse files
Code health: Pre-allocate row map capacity and document necessary clone in database.rs
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
1 parent 4c273b1 commit 0368aea

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎stdlib/src/database.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn std_database_query(
130130
None,
131131
)
132132
})? {
133-
let mut row_map = IndexMap::new();
133+
let mut row_map = IndexMap::with_capacity(column_names.len());
134134
for (idx, name) in column_names.iter().enumerate() {
135135
let value = match row.get_ref(idx).map_err(|e| {
136136
RuntimeError::new(
@@ -151,6 +151,8 @@ fn std_database_query(
151151
RuntimeValue::Str(s)
152152
}
153153
};
154+
// The clone here is strictly necessary because `IndexMap` requires an owned `String`
155+
// key, and each row constructs a fresh map containing these keys.
154156
row_map.insert(name.clone(), value);
155157
}
156158
result_rows.push(RuntimeValue::Map {

0 commit comments

Comments
 (0)