Add #[inline] and #[cold] in far more places

This commit is contained in:
Thom Chiovoloni
2020-11-03 19:10:23 -08:00
parent 7574124233
commit 65c38bf813
36 changed files with 366 additions and 32 deletions

View File

@@ -214,6 +214,7 @@ impl Connection {
/// Will return `Err` if `db`/`table`/`column` cannot be converted to a
/// C-compatible string or if the underlying SQLite BLOB open call
/// fails.
#[inline]
pub fn blob_open<'a>(
&'a self,
db: DatabaseName<'_>,
@@ -252,6 +253,7 @@ impl Blob<'_> {
/// # Failure
///
/// Will return `Err` if the underlying SQLite BLOB reopen call fails.
#[inline]
pub fn reopen(&mut self, row: i64) -> Result<()> {
let rc = unsafe { ffi::sqlite3_blob_reopen(self.blob, row) };
if rc != ffi::SQLITE_OK {
@@ -262,17 +264,20 @@ impl Blob<'_> {
}
/// Return the size in bytes of the BLOB.
#[inline]
pub fn size(&self) -> i32 {
unsafe { ffi::sqlite3_blob_bytes(self.blob) }
}
/// Return the current size in bytes of the BLOB.
#[inline]
pub fn len(&self) -> usize {
use std::convert::TryInto;
self.size().try_into().unwrap()
}
/// Return true if the BLOB is empty.
#[inline]
pub fn is_empty(&self) -> bool {
self.size() == 0
}
@@ -286,10 +291,12 @@ impl Blob<'_> {
/// # Failure
///
/// Will return `Err` if the underlying SQLite close call fails.
#[inline]
pub fn close(mut self) -> Result<()> {
self.close_()
}
#[inline]
fn close_(&mut self) -> Result<()> {
let rc = unsafe { ffi::sqlite3_blob_close(self.blob) };
self.blob = ptr::null_mut();
@@ -304,6 +311,7 @@ impl io::Read for Blob<'_> {
/// # Failure
///
/// Will return `Err` if the underlying SQLite read call fails.
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let max_allowed_len = (self.size() - self.pos) as usize;
let n = min(buf.len(), max_allowed_len) as i32;
@@ -334,6 +342,7 @@ impl io::Write for Blob<'_> {
/// # Failure
///
/// Will return `Err` if the underlying SQLite write call fails.
#[inline]
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let max_allowed_len = (self.size() - self.pos) as usize;
let n = min(buf.len(), max_allowed_len) as i32;
@@ -350,6 +359,7 @@ impl io::Write for Blob<'_> {
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
@@ -357,6 +367,7 @@ impl io::Write for Blob<'_> {
impl io::Seek for Blob<'_> {
/// Seek to an offset, in bytes, in BLOB.
#[inline]
fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
let pos = match pos {
io::SeekFrom::Start(offset) => offset as i64,
@@ -383,6 +394,7 @@ impl io::Seek for Blob<'_> {
#[allow(unused_must_use)]
impl Drop for Blob<'_> {
#[inline]
fn drop(&mut self) {
self.close_();
}
@@ -398,6 +410,7 @@ impl Drop for Blob<'_> {
pub struct ZeroBlob(pub i32);
impl ToSql for ZeroBlob {
#[inline]
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
let ZeroBlob(length) = *self;
Ok(ToSqlOutput::ZeroBlob(length))