Skip to content

Commit

Permalink
Update expand implementation to slightly improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sfauvel authored and dlachaume committed May 3, 2024
1 parent 7981e0c commit c3bd707
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions internal/mithril-persistence/src/sqlite/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ impl WhereCondition {
//
// Replace parameters placeholders by numerated parameters.
let mut final_expression = "".to_string();
let mut value = "".to_string();
let mut param_index = 0;
for sql_part in expression.split("?*") {
final_expression.push_str(&value);
for (param_index, sql_part) in expression.split("?*").enumerate() {
if param_index > 0 {
final_expression.push('?');
final_expression.push_str(&param_index.to_string());
}
final_expression.push_str(sql_part);
param_index += 1;
value = format!("?{}", param_index);
}

(final_expression.to_string(), parameters)
(final_expression, parameters)
}

/// Instanciate a condition with a `IN` statement.
Expand Down

0 comments on commit c3bd707

Please sign in to comment.