Put `#[inline]` on trivial functions
These functions either delegate to functions with identical signature or contain condition that may be optimized-out after inlining.
This commit is contained in:
parent
e531fa612b
commit
e1cc98986c
|
@ -20,15 +20,19 @@ pub struct TaprootMerkleBranch(Vec<TapNodeHash>);
|
|||
impl TaprootMerkleBranch {
|
||||
/// Returns a reference to the slice of hashes.
|
||||
#[deprecated(since = "TBD", note = "Use `as_slice` instead")]
|
||||
#[inline]
|
||||
pub fn as_inner(&self) -> &[TapNodeHash] { &self.0 }
|
||||
|
||||
/// Returns a reference to the slice of hashes.
|
||||
#[inline]
|
||||
pub fn as_slice(&self) -> &[TapNodeHash] { &self.0 }
|
||||
|
||||
/// Returns the number of nodes in this merkle proof.
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize { self.0.len() }
|
||||
|
||||
/// Checks if this merkle proof is empty.
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool { self.0.is_empty() }
|
||||
|
||||
/// Decodes bytes from control block.
|
||||
|
@ -62,6 +66,7 @@ impl TaprootMerkleBranch {
|
|||
///
|
||||
/// # Errors
|
||||
/// If inner proof length is more than [`TAPROOT_CONTROL_MAX_NODE_COUNT`] (128).
|
||||
#[inline]
|
||||
fn from_collection<T: AsRef<[TapNodeHash]> + Into<Vec<TapNodeHash>>>(
|
||||
collection: T,
|
||||
) -> Result<Self, TaprootError> {
|
||||
|
@ -101,9 +106,11 @@ impl TaprootMerkleBranch {
|
|||
|
||||
/// Returns the inner list of hashes.
|
||||
#[deprecated(since = "TBD", note = "Use `into_vec` instead")]
|
||||
#[inline]
|
||||
pub fn into_inner(self) -> Vec<TapNodeHash> { self.0 }
|
||||
|
||||
/// Returns the list of hashes stored in a `Vec`.
|
||||
#[inline]
|
||||
pub fn into_vec(self) -> Vec<TapNodeHash> { self.0 }
|
||||
}
|
||||
|
||||
|
@ -116,6 +123,7 @@ macro_rules! impl_try_from {
|
|||
///
|
||||
/// # Errors
|
||||
/// If inner proof length is more than [`TAPROOT_CONTROL_MAX_NODE_COUNT`] (128).
|
||||
#[inline]
|
||||
fn try_from(v: $from) -> Result<Self, Self::Error> {
|
||||
TaprootMerkleBranch::from_collection(v)
|
||||
}
|
||||
|
@ -130,6 +138,7 @@ macro_rules! impl_try_from_array {
|
|||
($($len:expr),* $(,)?) => {
|
||||
$(
|
||||
impl From<[TapNodeHash; $len]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn from(a: [TapNodeHash; $len]) -> Self {
|
||||
Self(a.to_vec())
|
||||
}
|
||||
|
@ -151,6 +160,7 @@ impl_try_from_array!(
|
|||
);
|
||||
|
||||
impl From<TaprootMerkleBranch> for Vec<TapNodeHash> {
|
||||
#[inline]
|
||||
fn from(branch: TaprootMerkleBranch) -> Self { branch.0 }
|
||||
}
|
||||
|
||||
|
@ -158,6 +168,7 @@ impl IntoIterator for TaprootMerkleBranch {
|
|||
type IntoIter = IntoIter;
|
||||
type Item = TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
IntoIter(self.0.into_iter())
|
||||
}
|
||||
|
@ -167,6 +178,7 @@ impl<'a> IntoIterator for &'a TaprootMerkleBranch {
|
|||
type IntoIter = core::slice::Iter<'a, TapNodeHash>;
|
||||
type Item = &'a TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter()
|
||||
}
|
||||
|
@ -176,6 +188,7 @@ impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
|
|||
type IntoIter = core::slice::IterMut<'a, TapNodeHash>;
|
||||
type Item = &'a mut TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter_mut()
|
||||
}
|
||||
|
@ -184,36 +197,42 @@ impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
|
|||
impl core::ops::Deref for TaprootMerkleBranch {
|
||||
type Target = [TapNodeHash];
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::DerefMut for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &[TapNodeHash] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn as_mut(&mut self) -> &mut [TapNodeHash] {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Borrow<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &[TapNodeHash] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl BorrowMut<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn borrow_mut(&mut self) -> &mut [TapNodeHash] {
|
||||
&mut self.0
|
||||
}
|
||||
|
@ -227,11 +246,13 @@ pub struct IntoIter(alloc::vec::IntoIter<TapNodeHash>);
|
|||
|
||||
impl IntoIter {
|
||||
/// Returns the remaining items of this iterator as a slice.
|
||||
#[inline]
|
||||
pub fn as_slice(&self) -> &[TapNodeHash] {
|
||||
self.0.as_slice()
|
||||
}
|
||||
|
||||
/// Returns the remaining items of this iterator as a mutable slice.
|
||||
#[inline]
|
||||
pub fn as_mut_slice(&mut self) -> &mut [TapNodeHash] {
|
||||
self.0.as_mut_slice()
|
||||
}
|
||||
|
@ -240,32 +261,39 @@ impl IntoIter {
|
|||
impl Iterator for IntoIter {
|
||||
type Item = TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.0.next()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.0.size_hint()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.0.nth(n)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn last(self) -> Option<Self::Item> {
|
||||
self.0.last()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn count(self) -> usize {
|
||||
self.0.count()
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleEndedIterator for IntoIter {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
self.0.next_back()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.0.nth_back(n)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue