mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 13:58:55 +08:00 
			
		
		
		
	Add #[inline] and #[cold] in far more places
				
					
				
			This commit is contained in:
		| @@ -51,6 +51,7 @@ pub(crate) unsafe extern "C" fn free_array(p: *mut c_void) { | ||||
| pub type Array = Rc<Vec<Value>>; | ||||
|  | ||||
| impl ToSql for Array { | ||||
|     #[inline] | ||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { | ||||
|         Ok(ToSqlOutput::Array(self.clone())) | ||||
|     } | ||||
|   | ||||
| @@ -354,6 +354,7 @@ unsafe impl VTabCursor for CSVTabCursor<'_> { | ||||
| } | ||||
|  | ||||
| impl From<csv::Error> for Error { | ||||
|     #[cold] | ||||
|     fn from(err: csv::Error) -> Error { | ||||
|         Error::ModuleError(err.to_string()) | ||||
|     } | ||||
|   | ||||
| @@ -310,6 +310,7 @@ pub struct IndexInfo(*mut ffi::sqlite3_index_info); | ||||
|  | ||||
| impl IndexInfo { | ||||
|     /// Record WHERE clause constraints. | ||||
|     #[inline] | ||||
|     pub fn constraints(&self) -> IndexConstraintIter<'_> { | ||||
|         let constraints = | ||||
|             unsafe { slice::from_raw_parts((*self.0).aConstraint, (*self.0).nConstraint as usize) }; | ||||
| @@ -319,6 +320,7 @@ impl IndexInfo { | ||||
|     } | ||||
|  | ||||
|     /// Information about the ORDER BY clause. | ||||
|     #[inline] | ||||
|     pub fn order_bys(&self) -> OrderByIter<'_> { | ||||
|         let order_bys = | ||||
|             unsafe { slice::from_raw_parts((*self.0).aOrderBy, (*self.0).nOrderBy as usize) }; | ||||
| @@ -328,11 +330,13 @@ impl IndexInfo { | ||||
|     } | ||||
|  | ||||
|     /// Number of terms in the ORDER BY clause | ||||
|     #[inline] | ||||
|     pub fn num_of_order_by(&self) -> usize { | ||||
|         unsafe { (*self.0).nOrderBy as usize } | ||||
|     } | ||||
|  | ||||
|     /// Information about what parameters to pass to `VTabCursor.filter`. | ||||
|     #[inline] | ||||
|     pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage<'_> { | ||||
|         let constraint_usages = unsafe { | ||||
|             slice::from_raw_parts_mut((*self.0).aConstraintUsage, (*self.0).nConstraint as usize) | ||||
| @@ -341,6 +345,7 @@ impl IndexInfo { | ||||
|     } | ||||
|  | ||||
|     /// Number used to identify the index | ||||
|     #[inline] | ||||
|     pub fn set_idx_num(&mut self, idx_num: c_int) { | ||||
|         unsafe { | ||||
|             (*self.0).idxNum = idx_num; | ||||
| @@ -348,6 +353,7 @@ impl IndexInfo { | ||||
|     } | ||||
|  | ||||
|     /// True if output is already ordered | ||||
|     #[inline] | ||||
|     pub fn set_order_by_consumed(&mut self, order_by_consumed: bool) { | ||||
|         unsafe { | ||||
|             (*self.0).orderByConsumed = if order_by_consumed { 1 } else { 0 }; | ||||
| @@ -355,6 +361,7 @@ impl IndexInfo { | ||||
|     } | ||||
|  | ||||
|     /// Estimated cost of using this index | ||||
|     #[inline] | ||||
|     pub fn set_estimated_cost(&mut self, estimated_ost: f64) { | ||||
|         unsafe { | ||||
|             (*self.0).estimatedCost = estimated_ost; | ||||
| @@ -363,6 +370,7 @@ impl IndexInfo { | ||||
|  | ||||
|     /// Estimated number of rows returned. | ||||
|     #[cfg(feature = "modern_sqlite")] // SQLite >= 3.8.2 | ||||
|     #[inline] | ||||
|     pub fn set_estimated_rows(&mut self, estimated_rows: i64) { | ||||
|         unsafe { | ||||
|             (*self.0).estimatedRows = estimated_rows; | ||||
| @@ -383,10 +391,12 @@ pub struct IndexConstraintIter<'a> { | ||||
| impl<'a> Iterator for IndexConstraintIter<'a> { | ||||
|     type Item = IndexConstraint<'a>; | ||||
|  | ||||
|     #[inline] | ||||
|     fn next(&mut self) -> Option<IndexConstraint<'a>> { | ||||
|         self.iter.next().map(|raw| IndexConstraint(raw)) | ||||
|     } | ||||
|  | ||||
|     #[inline] | ||||
|     fn size_hint(&self) -> (usize, Option<usize>) { | ||||
|         self.iter.size_hint() | ||||
|     } | ||||
| @@ -397,16 +407,19 @@ pub struct IndexConstraint<'a>(&'a ffi::sqlite3_index_constraint); | ||||
|  | ||||
| impl IndexConstraint<'_> { | ||||
|     /// Column constrained.  -1 for ROWID | ||||
|     #[inline] | ||||
|     pub fn column(&self) -> c_int { | ||||
|         self.0.iColumn | ||||
|     } | ||||
|  | ||||
|     /// Constraint operator | ||||
|     #[inline] | ||||
|     pub fn operator(&self) -> IndexConstraintOp { | ||||
|         IndexConstraintOp::from(self.0.op) | ||||
|     } | ||||
|  | ||||
|     /// True if this constraint is usable | ||||
|     #[inline] | ||||
|     pub fn is_usable(&self) -> bool { | ||||
|         self.0.usable != 0 | ||||
|     } | ||||
| @@ -418,11 +431,13 @@ pub struct IndexConstraintUsage<'a>(&'a mut ffi::sqlite3_index_constraint_usage) | ||||
|  | ||||
| impl IndexConstraintUsage<'_> { | ||||
|     /// if `argv_index` > 0, constraint is part of argv to `VTabCursor.filter` | ||||
|     #[inline] | ||||
|     pub fn set_argv_index(&mut self, argv_index: c_int) { | ||||
|         self.0.argvIndex = argv_index; | ||||
|     } | ||||
|  | ||||
|     /// if `omit`, do not code a test for this constraint | ||||
|     #[inline] | ||||
|     pub fn set_omit(&mut self, omit: bool) { | ||||
|         self.0.omit = if omit { 1 } else { 0 }; | ||||
|     } | ||||
| @@ -436,10 +451,12 @@ pub struct OrderByIter<'a> { | ||||
| impl<'a> Iterator for OrderByIter<'a> { | ||||
|     type Item = OrderBy<'a>; | ||||
|  | ||||
|     #[inline] | ||||
|     fn next(&mut self) -> Option<OrderBy<'a>> { | ||||
|         self.iter.next().map(|raw| OrderBy(raw)) | ||||
|     } | ||||
|  | ||||
|     #[inline] | ||||
|     fn size_hint(&self) -> (usize, Option<usize>) { | ||||
|         self.iter.size_hint() | ||||
|     } | ||||
| @@ -450,11 +467,13 @@ pub struct OrderBy<'a>(&'a ffi::sqlite3_index_info_sqlite3_index_orderby); | ||||
|  | ||||
| impl OrderBy<'_> { | ||||
|     /// Column number | ||||
|     #[inline] | ||||
|     pub fn column(&self) -> c_int { | ||||
|         self.0.iColumn | ||||
|     } | ||||
|  | ||||
|     /// True for DESC.  False for ASC. | ||||
|     #[inline] | ||||
|     pub fn is_order_by_desc(&self) -> bool { | ||||
|         self.0.desc != 0 | ||||
|     } | ||||
| @@ -500,6 +519,7 @@ pub struct Context(*mut ffi::sqlite3_context); | ||||
|  | ||||
| impl Context { | ||||
|     /// Set current cell value | ||||
|     #[inline] | ||||
|     pub fn set_result<T: ToSql>(&mut self, value: &T) -> Result<()> { | ||||
|         let t = value.to_sql()?; | ||||
|         unsafe { set_result(self.0, &t) }; | ||||
| @@ -517,11 +537,13 @@ pub struct Values<'a> { | ||||
|  | ||||
| impl Values<'_> { | ||||
|     /// Returns the number of values. | ||||
|     #[inline] | ||||
|     pub fn len(&self) -> usize { | ||||
|         self.args.len() | ||||
|     } | ||||
|  | ||||
|     /// Returns `true` if there is no value. | ||||
|     #[inline] | ||||
|     pub fn is_empty(&self) -> bool { | ||||
|         self.args.is_empty() | ||||
|     } | ||||
| @@ -567,6 +589,7 @@ impl Values<'_> { | ||||
|     } | ||||
|  | ||||
|     /// Turns `Values` into an iterator. | ||||
|     #[inline] | ||||
|     pub fn iter(&self) -> ValueIter<'_> { | ||||
|         ValueIter { | ||||
|             iter: self.args.iter(), | ||||
| @@ -578,6 +601,7 @@ impl<'a> IntoIterator for &'a Values<'a> { | ||||
|     type IntoIter = ValueIter<'a>; | ||||
|     type Item = ValueRef<'a>; | ||||
|  | ||||
|     #[inline] | ||||
|     fn into_iter(self) -> ValueIter<'a> { | ||||
|         self.iter() | ||||
|     } | ||||
| @@ -591,12 +615,14 @@ pub struct ValueIter<'a> { | ||||
| impl<'a> Iterator for ValueIter<'a> { | ||||
|     type Item = ValueRef<'a>; | ||||
|  | ||||
|     #[inline] | ||||
|     fn next(&mut self) -> Option<ValueRef<'a>> { | ||||
|         self.iter | ||||
|             .next() | ||||
|             .map(|&raw| unsafe { ValueRef::from_value(raw) }) | ||||
|     } | ||||
|  | ||||
|     #[inline] | ||||
|     fn size_hint(&self) -> (usize, Option<usize>) { | ||||
|         self.iter.size_hint() | ||||
|     } | ||||
| @@ -607,6 +633,7 @@ impl Connection { | ||||
|     /// | ||||
|     /// Step 3 of [Creating New Virtual Table | ||||
|     /// Implementations](https://sqlite.org/vtab.html#creating_new_virtual_table_implementations). | ||||
|     #[inline] | ||||
|     pub fn create_module<'vtab, T: VTab<'vtab>>( | ||||
|         &self, | ||||
|         module_name: &str, | ||||
| @@ -977,6 +1004,7 @@ where | ||||
|  | ||||
| /// Virtual table cursors can set an error message by assigning a string to | ||||
| /// `zErrMsg`. | ||||
| #[cold] | ||||
| unsafe fn cursor_error<T>(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result<T>) -> c_int { | ||||
|     match result { | ||||
|         Ok(_) => ffi::SQLITE_OK, | ||||
| @@ -995,6 +1023,7 @@ unsafe fn cursor_error<T>(cursor: *mut ffi::sqlite3_vtab_cursor, result: Result< | ||||
|  | ||||
| /// Virtual tables methods can set an error message by assigning a string to | ||||
| /// `zErrMsg`. | ||||
| #[cold] | ||||
| unsafe fn set_err_msg(vtab: *mut ffi::sqlite3_vtab, err_msg: &str) { | ||||
|     if !(*vtab).zErrMsg.is_null() { | ||||
|         ffi::sqlite3_free((*vtab).zErrMsg as *mut c_void); | ||||
| @@ -1004,6 +1033,7 @@ unsafe fn set_err_msg(vtab: *mut ffi::sqlite3_vtab, err_msg: &str) { | ||||
|  | ||||
| /// To raise an error, the `column` method should use this method to set the | ||||
| /// error message and return the error code. | ||||
| #[cold] | ||||
| unsafe fn result_error<T>(ctx: *mut ffi::sqlite3_context, result: Result<T>) -> c_int { | ||||
|     match result { | ||||
|         Ok(_) => ffi::SQLITE_OK, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user