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