Cache param count and make statement cache more effective

This commit is contained in:
Thom Chiovoloni
2020-04-16 08:22:47 -07:00
committed by Thom Chiovoloni
parent 6485b324d7
commit a776f460e8
3 changed files with 62 additions and 9 deletions

View File

@@ -9,3 +9,18 @@ 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
}
}