java-topology/defects/diesel/patch/diesel-0002-owned-sqlite-row-column-name-hashmap.patch

53 lines
1.9 KiB
Diff

# UNDF: UNDF-2026-000000044
diff --git a/diesel/src/sqlite/connection/owned_row.rs b/diesel/src/sqlite/connection/owned_row.rs
index xxxxxxx..xxxxxxx 100644
--- a/diesel/src/sqlite/connection/owned_row.rs
+++ b/diesel/src/sqlite/connection/owned_row.rs
@@ -1,15 +1,22 @@
+use alloc::collections::BTreeMap;
+use alloc::string::String;
+use alloc::sync::Arc;
use super::sqlite_value::OwnedSqliteValue;
use crate::row::{Field, PartialRow, Row, RowIndex, RowSealed};
use crate::sqlite::Sqlite;
#[allow(missing_debug_implementations)]
pub struct OwnedSqliteRow {
pub(super) values: Vec<Option<OwnedSqliteValue>>,
pub(super) column_names: Arc<[Option<String>]>,
+ // diesel-0002 fix: pre-built index map for O(1) column-name lookup.
+ // OwnedSqliteRow is the long-lived row variant (used after statement close).
+ // Previously iter().position() was O(N_cols) per get("name") call.
+ pub(super) column_name_index: Arc<BTreeMap<String, usize>>,
}
impl OwnedSqliteRow {
pub(super) fn new(
values: Vec<Option<OwnedSqliteValue>>,
column_names: Arc<[Option<String>]>,
) -> Self {
+ let column_name_index: Arc<BTreeMap<String, usize>> = Arc::new(
+ column_names
+ .iter()
+ .enumerate()
+ .filter_map(|(i, n)| n.as_ref().map(|name| (name.clone(), i)))
+ .collect(),
+ );
OwnedSqliteRow {
values,
column_names,
+ column_name_index,
}
}
}
@@ -68,9 +80,8 @@ impl RowIndex<usize> for OwnedSqliteRow {
impl<'idx> RowIndex<&'idx str> for OwnedSqliteRow {
fn idx(&self, field_name: &'idx str) -> Option<usize> {
- self.column_names
- .iter()
- .position(|n| n.as_ref().map(|s| s as &str) == Some(field_name))
+ // diesel-0002 fix: O(1) BTreeMap lookup replaces O(N_cols) linear scan
+ self.column_name_index.get(field_name).copied()
}
}