mirror of
https://github.com/isar/rusqlite.git
synced 2025-10-19 06:18:56 +08:00
Add #[inline]
and #[cold]
in far more places
This commit is contained in:
@@ -102,6 +102,7 @@ impl Transaction<'_> {
|
||||
/// Even though we don't mutate the connection, we take a `&mut Connection`
|
||||
/// so as to prevent nested transactions on the same connection. For cases
|
||||
/// where this is unacceptable, [`Transaction::new_unchecked`] is available.
|
||||
#[inline]
|
||||
pub fn new(conn: &mut Connection, behavior: TransactionBehavior) -> Result<Transaction<'_>> {
|
||||
Self::new_unchecked(conn, behavior)
|
||||
}
|
||||
@@ -111,6 +112,7 @@ impl Transaction<'_> {
|
||||
/// If a transaction is already open, this will return an error. Where
|
||||
/// possible, [`Transaction::new`] should be preferred, as it provides a
|
||||
/// compile-time guarantee that transactions are not nested.
|
||||
#[inline]
|
||||
pub fn new_unchecked(
|
||||
conn: &Connection,
|
||||
behavior: TransactionBehavior,
|
||||
@@ -153,42 +155,50 @@ impl Transaction<'_> {
|
||||
/// tx.commit()
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn savepoint(&mut self) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth(self.conn, 1)
|
||||
}
|
||||
|
||||
/// Create a new savepoint with a custom savepoint name. See `savepoint()`.
|
||||
#[inline]
|
||||
pub fn savepoint_with_name<T: Into<String>>(&mut self, name: T) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth_and_name(self.conn, 1, name)
|
||||
}
|
||||
|
||||
/// Get the current setting for what happens to the transaction when it is
|
||||
/// dropped.
|
||||
#[inline]
|
||||
pub fn drop_behavior(&self) -> DropBehavior {
|
||||
self.drop_behavior
|
||||
}
|
||||
|
||||
/// Configure the transaction to perform the specified action when it is
|
||||
/// dropped.
|
||||
#[inline]
|
||||
pub fn set_drop_behavior(&mut self, drop_behavior: DropBehavior) {
|
||||
self.drop_behavior = drop_behavior
|
||||
}
|
||||
|
||||
/// A convenience method which consumes and commits a transaction.
|
||||
#[inline]
|
||||
pub fn commit(mut self) -> Result<()> {
|
||||
self.commit_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn commit_(&mut self) -> Result<()> {
|
||||
self.conn.execute_batch("COMMIT")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A convenience method which consumes and rolls back a transaction.
|
||||
#[inline]
|
||||
pub fn rollback(mut self) -> Result<()> {
|
||||
self.rollback_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rollback_(&mut self) -> Result<()> {
|
||||
self.conn.execute_batch("ROLLBACK")?;
|
||||
Ok(())
|
||||
@@ -199,10 +209,12 @@ impl Transaction<'_> {
|
||||
///
|
||||
/// Functionally equivalent to the `Drop` implementation, but allows
|
||||
/// callers to see any errors that occur.
|
||||
#[inline]
|
||||
pub fn finish(mut self) -> Result<()> {
|
||||
self.finish_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finish_(&mut self) -> Result<()> {
|
||||
if self.conn.is_autocommit() {
|
||||
return Ok(());
|
||||
@@ -219,6 +231,7 @@ impl Transaction<'_> {
|
||||
impl Deref for Transaction<'_> {
|
||||
type Target = Connection;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Connection {
|
||||
self.conn
|
||||
}
|
||||
@@ -226,12 +239,14 @@ impl Deref for Transaction<'_> {
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
impl Drop for Transaction<'_> {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
self.finish_();
|
||||
}
|
||||
}
|
||||
|
||||
impl Savepoint<'_> {
|
||||
#[inline]
|
||||
fn with_depth_and_name<T: Into<String>>(
|
||||
conn: &Connection,
|
||||
depth: u32,
|
||||
@@ -248,48 +263,57 @@ impl Savepoint<'_> {
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_depth(conn: &Connection, depth: u32) -> Result<Savepoint<'_>> {
|
||||
let name = format!("_rusqlite_sp_{}", depth);
|
||||
Savepoint::with_depth_and_name(conn, depth, name)
|
||||
}
|
||||
|
||||
/// Begin a new savepoint. Can be nested.
|
||||
#[inline]
|
||||
pub fn new(conn: &mut Connection) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth(conn, 0)
|
||||
}
|
||||
|
||||
/// Begin a new savepoint with a user-provided savepoint name.
|
||||
#[inline]
|
||||
pub fn with_name<T: Into<String>>(conn: &mut Connection, name: T) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth_and_name(conn, 0, name)
|
||||
}
|
||||
|
||||
/// Begin a nested savepoint.
|
||||
#[inline]
|
||||
pub fn savepoint(&mut self) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth(self.conn, self.depth + 1)
|
||||
}
|
||||
|
||||
/// Begin a nested savepoint with a user-provided savepoint name.
|
||||
#[inline]
|
||||
pub fn savepoint_with_name<T: Into<String>>(&mut self, name: T) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_depth_and_name(self.conn, self.depth + 1, name)
|
||||
}
|
||||
|
||||
/// Get the current setting for what happens to the savepoint when it is
|
||||
/// dropped.
|
||||
#[inline]
|
||||
pub fn drop_behavior(&self) -> DropBehavior {
|
||||
self.drop_behavior
|
||||
}
|
||||
|
||||
/// Configure the savepoint to perform the specified action when it is
|
||||
/// dropped.
|
||||
#[inline]
|
||||
pub fn set_drop_behavior(&mut self, drop_behavior: DropBehavior) {
|
||||
self.drop_behavior = drop_behavior
|
||||
}
|
||||
|
||||
/// A convenience method which consumes and commits a savepoint.
|
||||
#[inline]
|
||||
pub fn commit(mut self) -> Result<()> {
|
||||
self.commit_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn commit_(&mut self) -> Result<()> {
|
||||
self.conn.execute_batch(&format!("RELEASE {}", self.name))?;
|
||||
self.committed = true;
|
||||
@@ -302,6 +326,7 @@ impl Savepoint<'_> {
|
||||
///
|
||||
/// Unlike `Transaction`s, savepoints remain active after they have been
|
||||
/// rolled back, and can be rolled back again or committed.
|
||||
#[inline]
|
||||
pub fn rollback(&mut self) -> Result<()> {
|
||||
self.conn
|
||||
.execute_batch(&format!("ROLLBACK TO {}", self.name))
|
||||
@@ -312,10 +337,12 @@ impl Savepoint<'_> {
|
||||
///
|
||||
/// Functionally equivalent to the `Drop` implementation, but allows
|
||||
/// callers to see any errors that occur.
|
||||
#[inline]
|
||||
pub fn finish(mut self) -> Result<()> {
|
||||
self.finish_()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn finish_(&mut self) -> Result<()> {
|
||||
if self.committed {
|
||||
return Ok(());
|
||||
@@ -332,6 +359,7 @@ impl Savepoint<'_> {
|
||||
impl Deref for Savepoint<'_> {
|
||||
type Target = Connection;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Connection {
|
||||
self.conn
|
||||
}
|
||||
@@ -339,6 +367,7 @@ impl Deref for Savepoint<'_> {
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
impl Drop for Savepoint<'_> {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
self.finish_();
|
||||
}
|
||||
@@ -370,6 +399,7 @@ impl Connection {
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if the underlying SQLite call fails.
|
||||
#[inline]
|
||||
pub fn transaction(&mut self) -> Result<Transaction<'_>> {
|
||||
Transaction::new(self, TransactionBehavior::Deferred)
|
||||
}
|
||||
@@ -381,6 +411,7 @@ impl Connection {
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if the underlying SQLite call fails.
|
||||
#[inline]
|
||||
pub fn transaction_with_behavior(
|
||||
&mut self,
|
||||
behavior: TransactionBehavior,
|
||||
@@ -448,6 +479,7 @@ impl Connection {
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if the underlying SQLite call fails.
|
||||
#[inline]
|
||||
pub fn savepoint(&mut self) -> Result<Savepoint<'_>> {
|
||||
Savepoint::new(self)
|
||||
}
|
||||
@@ -459,6 +491,7 @@ impl Connection {
|
||||
/// # Failure
|
||||
///
|
||||
/// Will return `Err` if the underlying SQLite call fails.
|
||||
#[inline]
|
||||
pub fn savepoint_with_name<T: Into<String>>(&mut self, name: T) -> Result<Savepoint<'_>> {
|
||||
Savepoint::with_name(self, name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user