Skip to content

Commit 9ba2926

Browse files
committed
refactor(odbc): change OdbcBatch columns to use Arc for improved memory efficiency
This commit updates the OdbcBatch structure to store columns as an Arc array, enhancing memory management and reducing cloning overhead. The change is reflected in both the OdbcBatch definition and its instantiation within the ODBC bridge.
1 parent e9eb8d0 commit 9ba2926

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

sqlx-core/src/odbc/connection/odbc_bridge.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ where
246246

247247
let mut receiver_open = true;
248248

249+
let columns: Vec<OdbcColumn> = bindings.iter().map(|b| b.column.clone()).collect();
250+
let col_arc: Arc<[OdbcColumn]> = Arc::from(columns);
251+
249252
while let Some(batch) = row_set_cursor.fetch()? {
250253
// Create ColumnData instances that can be shared across rows
251254
let column_data: Vec<_> = bindings
@@ -257,7 +260,7 @@ where
257260
.collect();
258261

259262
let odbc_batch = Arc::new(OdbcBatch {
260-
columns: bindings.iter().map(|b| b.column.clone()).collect(),
263+
columns: Arc::clone(&col_arc),
261264
column_data,
262265
});
263266

sqlx-core/src/odbc/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77

88
#[derive(Debug, Clone)]
99
pub struct OdbcBatch {
10-
pub(crate) columns: Vec<OdbcColumn>,
10+
pub(crate) columns: Arc<[OdbcColumn]>,
1111
pub(crate) column_data: Vec<Arc<crate::odbc::ColumnData>>,
1212
}
1313

0 commit comments

Comments
 (0)