mirror of
https://github.com/isar/rusqlite.git
synced 2025-11-06 09:48:58 +08:00
Add #[inline] and #[cold] in far more places
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct RawStatement {
|
||||
}
|
||||
|
||||
impl RawStatement {
|
||||
#[inline]
|
||||
pub unsafe fn new(stmt: *mut ffi::sqlite3_stmt, tail: usize) -> RawStatement {
|
||||
RawStatement {
|
||||
ptr: stmt,
|
||||
@@ -38,31 +39,38 @@ impl RawStatement {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_null(&self) -> bool {
|
||||
self.ptr.is_null()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_statement_cache_key(&mut self, p: impl Into<Arc<str>>) {
|
||||
self.statement_cache_key = Some(p.into());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn statement_cache_key(&self) -> Option<Arc<str>> {
|
||||
self.statement_cache_key.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn ptr(&self) -> *mut ffi::sqlite3_stmt {
|
||||
self.ptr
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn column_count(&self) -> usize {
|
||||
// Note: Can't cache this as it changes if the schema is altered.
|
||||
unsafe { ffi::sqlite3_column_count(self.ptr) as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn column_type(&self, idx: usize) -> c_int {
|
||||
unsafe { ffi::sqlite3_column_type(self.ptr, idx as c_int) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "column_decltype")]
|
||||
pub fn column_decltype(&self, idx: usize) -> Option<&CStr> {
|
||||
unsafe {
|
||||
@@ -75,6 +83,7 @@ impl RawStatement {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn column_name(&self, idx: usize) -> Option<&CStr> {
|
||||
let idx = idx as c_int;
|
||||
if idx < 0 || idx >= self.column_count() as c_int {
|
||||
@@ -92,6 +101,7 @@ impl RawStatement {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "unlock_notify"), inline)]
|
||||
pub fn step(&self) -> c_int {
|
||||
if cfg!(feature = "unlock_notify") {
|
||||
let db = unsafe { ffi::sqlite3_db_handle(self.ptr) };
|
||||
@@ -113,14 +123,17 @@ impl RawStatement {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reset(&self) -> c_int {
|
||||
unsafe { ffi::sqlite3_reset(self.ptr) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bind_parameter_count(&self) -> usize {
|
||||
unsafe { ffi::sqlite3_bind_parameter_count(self.ptr) as usize }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn bind_parameter_index(&self, name: &str) -> Option<usize> {
|
||||
self.cache.get_or_insert_with(name, |param_cstr| {
|
||||
let r = unsafe { ffi::sqlite3_bind_parameter_index(self.ptr, param_cstr.as_ptr()) };
|
||||
@@ -131,10 +144,12 @@ impl RawStatement {
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn clear_bindings(&self) -> c_int {
|
||||
unsafe { ffi::sqlite3_clear_bindings(self.ptr) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn sql(&self) -> Option<&CStr> {
|
||||
if self.ptr.is_null() {
|
||||
None
|
||||
@@ -143,36 +158,43 @@ impl RawStatement {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finalize(mut self) -> c_int {
|
||||
self.finalize_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finalize_(&mut self) -> c_int {
|
||||
let r = unsafe { ffi::sqlite3_finalize(self.ptr) };
|
||||
self.ptr = ptr::null_mut();
|
||||
r
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(all(feature = "extra_check", feature = "modern_sqlite"))] // 3.7.4
|
||||
pub fn readonly(&self) -> bool {
|
||||
unsafe { ffi::sqlite3_stmt_readonly(self.ptr) != 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "modern_sqlite")] // 3.14.0
|
||||
pub(crate) fn expanded_sql(&self) -> Option<SqliteMallocString> {
|
||||
unsafe { SqliteMallocString::from_raw(ffi::sqlite3_expanded_sql(self.ptr)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_status(&self, status: StatementStatus, reset: bool) -> i32 {
|
||||
assert!(!self.ptr.is_null());
|
||||
unsafe { ffi::sqlite3_stmt_status(self.ptr, status as i32, reset as i32) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "extra_check")]
|
||||
pub fn has_tail(&self) -> bool {
|
||||
self.tail != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn tail(&self) -> usize {
|
||||
self.tail
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user