From 19b0772f3f673371459210929d235da25a9ef7bb Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Sun, 31 Jan 2021 15:40:55 -0800 Subject: [PATCH] Make it clear bind_in is not public, and inline functions passing large arrays by value to avoid too much copying --- src/params.rs | 17 +++++++++-------- src/statement.rs | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/params.rs b/src/params.rs index be1e400..dc174c6 100644 --- a/src/params.rs +++ b/src/params.rs @@ -163,7 +163,7 @@ pub trait Params: Sealed { // // For now, just hide the function in the docs... #[doc(hidden)] - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()>; + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()>; } // Explicitly impl for empty array. Critically, for `conn.execute([])` to be @@ -172,7 +172,7 @@ pub trait Params: Sealed { impl Sealed for [&dyn ToSql; 0] {} impl Params for [&dyn ToSql; 0] { #[inline] - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { // Note: Can't just return `Ok(())` — `Statement::bind_parameters` // checks that the right number of params were passed too. // TODO: we should have tests for `Error::InvalidParameterCount`... @@ -183,7 +183,7 @@ impl Params for [&dyn ToSql; 0] { impl Sealed for &[&dyn ToSql] {} impl Params for &[&dyn ToSql] { #[inline] - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters(self) } } @@ -191,7 +191,7 @@ impl Params for &[&dyn ToSql] { impl Sealed for &[(&str, &dyn ToSql)] {} impl Params for &[(&str, &dyn ToSql)] { #[inline] - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters_named(self) } } @@ -202,19 +202,20 @@ macro_rules! impl_for_array_ref { // avoid the compile time hit from making them all inline for now. impl Sealed for &[&T; $N] {} impl Params for &[&T; $N] { - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters(self) } } impl Sealed for &[(&str, &T); $N] {} impl Params for &[(&str, &T); $N] { - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters_named(self) } } impl Sealed for [T; $N] {} impl Params for [T; $N] { - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + #[inline] + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters(&self) } } @@ -351,7 +352,7 @@ where I::Item: ToSql, { #[inline] - fn bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { + fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { stmt.bind_parameters(self.0) } } diff --git a/src/statement.rs b/src/statement.rs index f808ce4..e6419dc 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -82,7 +82,7 @@ impl Statement<'_> { /// underlying SQLite call fails. #[inline] pub fn execute(&mut self, params: P) -> Result { - params.bind_in(self)?; + params.__bind_in(self)?; self.execute_with_bound_parameters() } @@ -221,7 +221,7 @@ impl Statement<'_> { #[inline] pub fn query(&mut self, params: P) -> Result> { self.check_readonly()?; - params.bind_in(self)?; + params.__bind_in(self)?; Ok(Rows::new(self)) }