mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
Remove parameter count caching -- should be cheap (if statically linked at least...)
This commit is contained in:
parent
a776f460e8
commit
d88fe1c1b1
@ -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> {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user