Skip to content

Commit

Permalink
avoid potentially expensive operations on prepare
Browse files Browse the repository at this point in the history
This simple patch makes sure we can operate with a reference to the
string instead of being forced to transform it to a string, and makes
sure that the Arc doesn't have to be cloned (which can be expensive in
multi-core systems).

This doesn't really make a large difference in benchmarks, given how
expensive Parse::new() is.
  • Loading branch information
glommer committed Jan 28, 2025
1 parent ac18880 commit a975a44
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ pub struct Connection {
}

impl Connection {
pub fn prepare(self: &Rc<Connection>, sql: impl Into<String>) -> Result<Statement> {
let sql = sql.into();
pub fn prepare(self: &Rc<Connection>, sql: impl AsRef<str>) -> Result<Statement> {
let sql = sql.as_ref();
trace!("Preparing: {}", sql);
let db = self.db.clone();
let db = &self.db;
let syms: &SymbolTable = &db.syms.borrow();
let mut parser = Parser::new(sql.as_bytes());
let cmd = parser.next()?;
Expand Down

0 comments on commit a975a44

Please sign in to comment.