mirror of
https://github.com/isar/rusqlite.git
synced 2025-11-05 09:18:57 +08:00
Add #[inline] and #[cold] in far more places
This commit is contained in:
@@ -29,11 +29,13 @@ pub struct Session<'conn> {
|
||||
|
||||
impl Session<'_> {
|
||||
/// Create a new session object
|
||||
#[inline]
|
||||
pub fn new(db: &Connection) -> Result<Session<'_>> {
|
||||
Session::new_with_name(db, DatabaseName::Main)
|
||||
}
|
||||
|
||||
/// Create a new session object
|
||||
#[inline]
|
||||
pub fn new_with_name<'conn>(
|
||||
db: &'conn Connection,
|
||||
name: DatabaseName<'_>,
|
||||
@@ -120,6 +122,7 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
/// Write the set of changes represented by this session to `output`.
|
||||
#[inline]
|
||||
pub fn changeset_strm(&mut self, output: &mut dyn Write) -> Result<()> {
|
||||
let output_ref = &output;
|
||||
check!(unsafe {
|
||||
@@ -133,6 +136,7 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
/// Generate a Patchset
|
||||
#[inline]
|
||||
pub fn patchset(&mut self) -> Result<Changeset> {
|
||||
let mut n = 0;
|
||||
let mut ps: *mut c_void = ptr::null_mut();
|
||||
@@ -142,6 +146,7 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
/// Write the set of patches represented by this session to `output`.
|
||||
#[inline]
|
||||
pub fn patchset_strm(&mut self, output: &mut dyn Write) -> Result<()> {
|
||||
let output_ref = &output;
|
||||
check!(unsafe {
|
||||
@@ -174,16 +179,19 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
/// Test if a changeset has recorded any changes
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
unsafe { ffi::sqlite3session_isempty(self.s) != 0 }
|
||||
}
|
||||
|
||||
/// Query the current state of the session
|
||||
#[inline]
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
unsafe { ffi::sqlite3session_enable(self.s, -1) != 0 }
|
||||
}
|
||||
|
||||
/// Enable or disable the recording of changes
|
||||
#[inline]
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
unsafe {
|
||||
ffi::sqlite3session_enable(self.s, if enabled { 1 } else { 0 });
|
||||
@@ -191,11 +199,13 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
/// Query the current state of the indirect flag
|
||||
#[inline]
|
||||
pub fn is_indirect(&self) -> bool {
|
||||
unsafe { ffi::sqlite3session_indirect(self.s, -1) != 0 }
|
||||
}
|
||||
|
||||
/// Set or clear the indirect change flag
|
||||
#[inline]
|
||||
pub fn set_indirect(&mut self, indirect: bool) {
|
||||
unsafe {
|
||||
ffi::sqlite3session_indirect(self.s, if indirect { 1 } else { 0 });
|
||||
@@ -204,6 +214,7 @@ impl Session<'_> {
|
||||
}
|
||||
|
||||
impl Drop for Session<'_> {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
if self.filter.is_some() {
|
||||
self.table_filter(None::<fn(&str) -> bool>);
|
||||
@@ -213,6 +224,7 @@ impl Drop for Session<'_> {
|
||||
}
|
||||
|
||||
/// `feature = "session"` Invert a changeset
|
||||
#[inline]
|
||||
pub fn invert_strm(input: &mut dyn Read, output: &mut dyn Write) -> Result<()> {
|
||||
let input_ref = &input;
|
||||
let output_ref = &output;
|
||||
@@ -228,6 +240,7 @@ pub fn invert_strm(input: &mut dyn Read, output: &mut dyn Write) -> Result<()> {
|
||||
}
|
||||
|
||||
/// `feature = "session"` Combine two changesets
|
||||
#[inline]
|
||||
pub fn concat_strm(
|
||||
input_a: &mut dyn Read,
|
||||
input_b: &mut dyn Read,
|
||||
@@ -257,6 +270,7 @@ pub struct Changeset {
|
||||
|
||||
impl Changeset {
|
||||
/// Invert a changeset
|
||||
#[inline]
|
||||
pub fn invert(&self) -> Result<Changeset> {
|
||||
let mut n = 0;
|
||||
let mut cs = ptr::null_mut();
|
||||
@@ -267,6 +281,7 @@ impl Changeset {
|
||||
}
|
||||
|
||||
/// Create an iterator to traverse a changeset
|
||||
#[inline]
|
||||
pub fn iter(&self) -> Result<ChangesetIter<'_>> {
|
||||
let mut it = ptr::null_mut();
|
||||
check!(unsafe { ffi::sqlite3changeset_start(&mut it as *mut *mut _, self.n, self.cs) });
|
||||
@@ -278,6 +293,7 @@ impl Changeset {
|
||||
}
|
||||
|
||||
/// Concatenate two changeset objects
|
||||
#[inline]
|
||||
pub fn concat(a: &Changeset, b: &Changeset) -> Result<Changeset> {
|
||||
let mut n = 0;
|
||||
let mut cs = ptr::null_mut();
|
||||
@@ -289,6 +305,7 @@ impl Changeset {
|
||||
}
|
||||
|
||||
impl Drop for Changeset {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
ffi::sqlite3_free(self.cs);
|
||||
@@ -306,6 +323,7 @@ pub struct ChangesetIter<'changeset> {
|
||||
|
||||
impl ChangesetIter<'_> {
|
||||
/// Create an iterator on `input`
|
||||
#[inline]
|
||||
pub fn start_strm<'input>(input: &&'input mut dyn Read) -> Result<ChangesetIter<'input>> {
|
||||
let mut it = ptr::null_mut();
|
||||
check!(unsafe {
|
||||
@@ -327,6 +345,7 @@ impl FallibleStreamingIterator for ChangesetIter<'_> {
|
||||
type Error = crate::error::Error;
|
||||
type Item = ChangesetItem;
|
||||
|
||||
#[inline]
|
||||
fn advance(&mut self) -> Result<()> {
|
||||
let rc = unsafe { ffi::sqlite3changeset_next(self.it) };
|
||||
match rc {
|
||||
@@ -342,6 +361,7 @@ impl FallibleStreamingIterator for ChangesetIter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get(&self) -> Option<&ChangesetItem> {
|
||||
self.item.as_ref()
|
||||
}
|
||||
@@ -357,27 +377,32 @@ pub struct Operation<'item> {
|
||||
|
||||
impl Operation<'_> {
|
||||
/// Returns the table name.
|
||||
#[inline]
|
||||
pub fn table_name(&self) -> &str {
|
||||
self.table_name
|
||||
}
|
||||
|
||||
/// Returns the number of columns in table
|
||||
#[inline]
|
||||
pub fn number_of_columns(&self) -> i32 {
|
||||
self.number_of_columns
|
||||
}
|
||||
|
||||
/// Returns the action code.
|
||||
#[inline]
|
||||
pub fn code(&self) -> Action {
|
||||
self.code
|
||||
}
|
||||
|
||||
/// Returns `true` for an 'indirect' change.
|
||||
#[inline]
|
||||
pub fn indirect(&self) -> bool {
|
||||
self.indirect
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ChangesetIter<'_> {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
ffi::sqlite3changeset_finalize(self.it);
|
||||
@@ -397,6 +422,7 @@ impl ChangesetItem {
|
||||
///
|
||||
/// May only be called with an `SQLITE_CHANGESET_DATA` or
|
||||
/// `SQLITE_CHANGESET_CONFLICT` conflict handler callback.
|
||||
#[inline]
|
||||
pub fn conflict(&self, col: usize) -> Result<ValueRef<'_>> {
|
||||
unsafe {
|
||||
let mut p_value: *mut ffi::sqlite3_value = ptr::null_mut();
|
||||
@@ -413,6 +439,7 @@ impl ChangesetItem {
|
||||
///
|
||||
/// May only be called with an `SQLITE_CHANGESET_FOREIGN_KEY` conflict
|
||||
/// handler callback.
|
||||
#[inline]
|
||||
pub fn fk_conflicts(&self) -> Result<i32> {
|
||||
unsafe {
|
||||
let mut p_out = 0;
|
||||
@@ -425,6 +452,7 @@ impl ChangesetItem {
|
||||
///
|
||||
/// May only be called if the type of change is either `SQLITE_UPDATE` or
|
||||
/// `SQLITE_INSERT`.
|
||||
#[inline]
|
||||
pub fn new_value(&self, col: usize) -> Result<ValueRef<'_>> {
|
||||
unsafe {
|
||||
let mut p_value: *mut ffi::sqlite3_value = ptr::null_mut();
|
||||
@@ -437,6 +465,7 @@ impl ChangesetItem {
|
||||
///
|
||||
/// May only be called if the type of change is either `SQLITE_DELETE` or
|
||||
/// `SQLITE_UPDATE`.
|
||||
#[inline]
|
||||
pub fn old_value(&self, col: usize) -> Result<ValueRef<'_>> {
|
||||
unsafe {
|
||||
let mut p_value: *mut ffi::sqlite3_value = ptr::null_mut();
|
||||
@@ -446,6 +475,7 @@ impl ChangesetItem {
|
||||
}
|
||||
|
||||
/// Obtain the current operation
|
||||
#[inline]
|
||||
pub fn op(&self) -> Result<Operation<'_>> {
|
||||
let mut number_of_columns = 0;
|
||||
let mut code = 0;
|
||||
@@ -471,6 +501,7 @@ impl ChangesetItem {
|
||||
}
|
||||
|
||||
/// Obtain the primary key definition of a table
|
||||
#[inline]
|
||||
pub fn pk(&self) -> Result<&[u8]> {
|
||||
let mut number_of_columns = 0;
|
||||
unsafe {
|
||||
@@ -493,6 +524,7 @@ pub struct Changegroup {
|
||||
|
||||
impl Changegroup {
|
||||
/// Create a new change group.
|
||||
#[inline]
|
||||
pub fn new() -> Result<Self> {
|
||||
let mut cg = ptr::null_mut();
|
||||
check!(unsafe { ffi::sqlite3changegroup_new(&mut cg) });
|
||||
@@ -500,12 +532,14 @@ impl Changegroup {
|
||||
}
|
||||
|
||||
/// Add a changeset
|
||||
#[inline]
|
||||
pub fn add(&mut self, cs: &Changeset) -> Result<()> {
|
||||
check!(unsafe { ffi::sqlite3changegroup_add(self.cg, cs.n, cs.cs) });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a changeset read from `input` to this change group.
|
||||
#[inline]
|
||||
pub fn add_stream(&mut self, input: &mut dyn Read) -> Result<()> {
|
||||
let input_ref = &input;
|
||||
check!(unsafe {
|
||||
@@ -519,6 +553,7 @@ impl Changegroup {
|
||||
}
|
||||
|
||||
/// Obtain a composite Changeset
|
||||
#[inline]
|
||||
pub fn output(&mut self) -> Result<Changeset> {
|
||||
let mut n = 0;
|
||||
let mut output: *mut c_void = ptr::null_mut();
|
||||
@@ -527,6 +562,7 @@ impl Changegroup {
|
||||
}
|
||||
|
||||
/// Write the combined set of changes to `output`.
|
||||
#[inline]
|
||||
pub fn output_strm(&mut self, output: &mut dyn Write) -> Result<()> {
|
||||
let output_ref = &output;
|
||||
check!(unsafe {
|
||||
@@ -541,6 +577,7 @@ impl Changegroup {
|
||||
}
|
||||
|
||||
impl Drop for Changegroup {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
ffi::sqlite3changegroup_delete(self.cg);
|
||||
|
||||
Reference in New Issue
Block a user