mirror of
https://github.com/isar/rusqlite.git
synced 2025-12-21 19:02:23 +08:00
Add #[inline] and #[cold] in far more places
This commit is contained in:
11
src/cache.rs
11
src/cache.rs
@@ -34,6 +34,7 @@ impl Connection {
|
||||
///
|
||||
/// Will return `Err` if `sql` cannot be converted to a C-compatible string
|
||||
/// or if the underlying SQLite call fails.
|
||||
#[inline]
|
||||
pub fn prepare_cached(&self, sql: &str) -> Result<CachedStatement<'_>> {
|
||||
self.cache.get(self, sql)
|
||||
}
|
||||
@@ -43,11 +44,13 @@ impl Connection {
|
||||
/// number of cached statements. If you need more, or know that you
|
||||
/// will not use cached statements, you
|
||||
/// can set the capacity manually using this method.
|
||||
#[inline]
|
||||
pub fn set_prepared_statement_cache_capacity(&self, capacity: usize) {
|
||||
self.cache.set_capacity(capacity)
|
||||
}
|
||||
|
||||
/// Remove/finalize all prepared statements currently in the cache.
|
||||
#[inline]
|
||||
pub fn flush_prepared_statement_cache(&self) {
|
||||
self.cache.flush()
|
||||
}
|
||||
@@ -69,12 +72,14 @@ pub struct CachedStatement<'conn> {
|
||||
impl<'conn> Deref for CachedStatement<'conn> {
|
||||
type Target = Statement<'conn>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Statement<'conn> {
|
||||
self.stmt.as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'conn> DerefMut for CachedStatement<'conn> {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Statement<'conn> {
|
||||
self.stmt.as_mut().unwrap()
|
||||
}
|
||||
@@ -82,6 +87,7 @@ impl<'conn> DerefMut for CachedStatement<'conn> {
|
||||
|
||||
impl Drop for CachedStatement<'_> {
|
||||
#[allow(unused_must_use)]
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
if let Some(stmt) = self.stmt.take() {
|
||||
self.cache.cache_stmt(unsafe { stmt.into_raw() });
|
||||
@@ -90,6 +96,7 @@ impl Drop for CachedStatement<'_> {
|
||||
}
|
||||
|
||||
impl CachedStatement<'_> {
|
||||
#[inline]
|
||||
fn new<'conn>(stmt: Statement<'conn>, cache: &'conn StatementCache) -> CachedStatement<'conn> {
|
||||
CachedStatement {
|
||||
stmt: Some(stmt),
|
||||
@@ -99,6 +106,7 @@ impl CachedStatement<'_> {
|
||||
|
||||
/// Discard the statement, preventing it from being returned to its
|
||||
/// `Connection`'s collection of cached statements.
|
||||
#[inline]
|
||||
pub fn discard(mut self) {
|
||||
self.stmt = None;
|
||||
}
|
||||
@@ -106,10 +114,12 @@ impl CachedStatement<'_> {
|
||||
|
||||
impl StatementCache {
|
||||
/// Create a statement cache.
|
||||
#[inline]
|
||||
pub fn with_capacity(capacity: usize) -> StatementCache {
|
||||
StatementCache(RefCell::new(LruCache::new(capacity)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_capacity(&self, capacity: usize) {
|
||||
self.0.borrow_mut().set_capacity(capacity)
|
||||
}
|
||||
@@ -155,6 +165,7 @@ impl StatementCache {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn flush(&self) {
|
||||
let mut cache = self.0.borrow_mut();
|
||||
cache.clear()
|
||||
|
||||
Reference in New Issue
Block a user