Remove parameter count caching -- should be cheap (if statically linked at least...)

This commit is contained in:
Thom Chiovoloni 2020-04-16 11:08:36 -07:00 committed by Thom Chiovoloni
parent a776f460e8
commit d88fe1c1b1
2 changed files with 1 additions and 22 deletions

View File

@ -3,7 +3,6 @@ use super::unlock_notify;
use super::StatementStatus;
#[cfg(feature = "modern_sqlite")]
use crate::util::SqliteMallocString;
use std::cell::Cell;
use std::ffi::CStr;
use std::os::raw::c_int;
use std::ptr;
@ -16,8 +15,6 @@ pub struct RawStatement {
tail: bool,
// Cached indices of named parameters, computed on the fly.
cache: crate::util::ParamIndexCache,
// Cached count of named parameters, computed on first use.
bind_parameter_count: Cell<Option<usize>>,
// Cached SQL (trimmed) that we use as the key when we're in the statement
// cache. This is None for statements which didn't come from the statement
// cache.
@ -36,7 +33,6 @@ impl RawStatement {
RawStatement {
ptr: stmt,
tail,
bind_parameter_count: Cell::new(None),
cache: Default::default(),
statement_cache_key: None,
}
@ -121,9 +117,7 @@ impl RawStatement {
}
pub fn bind_parameter_count(&self) -> usize {
crate::util::get_cached(&self.bind_parameter_count, || unsafe {
ffi::sqlite3_bind_parameter_count(self.ptr) as usize
})
unsafe { ffi::sqlite3_bind_parameter_count(self.ptr) as usize }
}
pub fn bind_parameter_index(&self, name: &str) -> Option<usize> {

View File

@ -9,18 +9,3 @@ pub(crate) use small_cstr::SmallCString;
mod sqlite_string;
#[cfg(any(feature = "modern_sqlite", feature = "vtab"))]
pub(crate) use sqlite_string::SqliteMallocString;
#[inline]
pub(crate) fn get_cached<T, F>(cache: &std::cell::Cell<Option<T>>, lookup: F) -> T
where
T: Copy,
F: FnOnce() -> T,
{
if let Some(v) = cache.get() {
v
} else {
let cb = lookup();
cache.set(Some(cb));
cb
}
}