From 9e1e5d7c428f960d896de79e5c79f0c4ffca2680 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 1 Jul 2025 15:20:30 +0000
Subject: [PATCH] chore: Inline small functions
Signed-off-by: Awiteb
---
src/cli/commands/issue/mod.rs | 4 ++++
src/cli/commands/patch/mod.rs | 5 +++++
src/nostr_utils/traits.rs | 14 ++++++++++++++
src/nostr_utils/utils.rs | 7 +++++++
4 files changed, 30 insertions(+)
diff --git a/src/cli/commands/issue/mod.rs b/src/cli/commands/issue/mod.rs
index 204f495..64a767e 100644
--- a/src/cli/commands/issue/mod.rs
+++ b/src/cli/commands/issue/mod.rs
@@ -66,6 +66,7 @@ pub enum IssueStatus {
impl IssueStatus {
/// Maps the issue status to its corresponding Nostr kind.
+ #[inline]
pub fn kind(&self) -> Kind {
match self {
Self::Open => Kind::GitStatusOpen,
@@ -75,16 +76,19 @@ impl IssueStatus {
}
/// Check if the issue is open.
+ #[inline]
pub fn is_open(&self) -> bool {
matches!(self, Self::Open)
}
/// Check if the issue is resolved.
+ #[inline]
pub fn is_resolved(&self) -> bool {
matches!(self, Self::Resolved)
}
/// Check if the issue is closed.
+ #[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed)
}
diff --git a/src/cli/commands/patch/mod.rs b/src/cli/commands/patch/mod.rs
index f9248ab..f12e04e 100644
--- a/src/cli/commands/patch/mod.rs
+++ b/src/cli/commands/patch/mod.rs
@@ -105,6 +105,7 @@ pub enum PatchStatus {
impl PatchStatus {
/// Maps the issue status to its corresponding Nostr kind.
+ #[inline]
pub fn kind(&self) -> Kind {
match self {
Self::Open => Kind::GitStatusOpen,
@@ -115,21 +116,25 @@ impl PatchStatus {
}
/// Check if the patch is open.
+ #[inline]
pub fn is_open(&self) -> bool {
matches!(self, Self::Open)
}
/// Check if the patch is merged/applied.
+ #[inline]
pub fn is_merged_or_applied(&self) -> bool {
matches!(self, Self::MergedApplied)
}
/// Check if the patch is closed.
+ #[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed)
}
/// Check if the patch is drafted
+ #[inline]
pub fn is_drafted(&self) -> bool {
matches!(self, Self::Draft)
}
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 5dee402..7fb853f 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -37,12 +37,14 @@ use crate::error::{N34Error, N34Result};
#[easy_ext::ext(TagsExt)]
impl Tags {
/// Search for the given tag and map it value to a function
+ #[inline]
pub fn map_tag(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> Option {
self.find_standardized(kind).map(f)
}
/// Search for the given tag and map it value to a function. If the tag not
/// found return the default `T`
+ #[inline]
pub fn dmap_tag(&self, kind: TagKind, f: impl FnOnce(&TagStandard) -> T) -> T
where
T: Default,
@@ -52,6 +54,7 @@ impl Tags {
/// Finds the first standard tag of the given kind with the specified
/// marker, then applies the function to the tag and returns the result.
+ #[inline]
pub fn map_marker(
&self,
kind: TagKind,
@@ -148,6 +151,7 @@ impl EventBuilder {
impl Token<'_> {
/// Returns `Some((public_key, relays))` from the givin token if it's npub1
/// or nprofile1
+ #[inline]
pub fn extract_public_key(&self) -> Option<(PublicKey, Vec)> {
match self {
Token::Nostr(nip21) => {
@@ -163,6 +167,7 @@ impl Token<'_> {
/// Returns `Some((note_id, relays))` from the givin token if it's note1 or
/// nevent1
+ #[inline]
pub fn extract_event_id(&self) -> Option<(EventId, Vec)> {
match self {
Token::Nostr(nip21) => {
@@ -177,6 +182,7 @@ impl Token<'_> {
}
/// Returns `Some(hashtag)` from the givin token if it's a hashtag
+ #[inline]
pub fn extract_hashtag(&self) -> Option {
match self {
Token::Hashtag(tag) => Some(tag.trim().to_owned()),
@@ -189,16 +195,19 @@ impl Token<'_> {
#[easy_ext::ext(NaddrsUtils)]
impl Vec {
/// Converts these coordinate addresses to basic coordinates
+ #[inline]
pub fn into_coordinates(self) -> Vec {
self.into_iter().map(|n| n.coordinate).collect()
}
/// Returns all repository owners' public keys from these coordinates.
+ #[inline]
pub fn extract_owners(&self) -> Vec {
self.iter().map(|n| n.public_key).collect()
}
/// Extracts all relay URLs from these coordinates
+ #[inline]
pub fn extract_relays(&self) -> Vec {
self.iter().flat_map(|n| n.relays.clone()).collect()
}
@@ -208,16 +217,19 @@ impl Vec {
#[easy_ext::ext(ReposUtils)]
impl Vec {
/// Extracts all relay URLs from these repositories
+ #[inline]
pub fn extract_relays(&self) -> Vec {
self.iter().flat_map(|n| n.relays.clone()).collect()
}
/// Extract all the maintainers from these repositories
+ #[inline]
pub fn extract_maintainers(&self) -> Vec {
self.iter().flat_map(|r| r.maintainers.clone()).collect()
}
/// Gets the first EUC hash from the reposotoies if it exists.
+ #[inline]
pub fn extract_euc(&self) -> Option<&Sha1Hash> {
self.iter().find_map(|r| r.euc.as_ref())
}
@@ -227,6 +239,7 @@ impl Vec {
#[easy_ext::ext(GitPatchUtils)]
impl Event {
/// Returns whether the patch is a root or not
+ #[inline]
pub fn is_root_patch(&self) -> bool {
self.kind == Kind::GitPatch
&& self
@@ -236,6 +249,7 @@ impl Event {
}
/// Returns whether the patch is patch-revision or not
+ #[inline]
pub fn is_revision_patch(&self) -> bool {
self.kind == Kind::GitPatch
&& self
diff --git a/src/nostr_utils/utils.rs b/src/nostr_utils/utils.rs
index 2939525..a404300 100644
--- a/src/nostr_utils/utils.rs
+++ b/src/nostr_utils/utils.rs
@@ -43,17 +43,20 @@ use crate::{
};
/// Returns the value of the given tag
+#[inline]
fn tag_value(tag: &TagStandard) -> String {
tag.clone().to_vec().remove(1)
}
/// Parses the tag value into type `T` if possible.
+#[inline]
fn parse_value(tag: &TagStandard) -> Option {
tag_value(tag).parse().ok()
}
/// Gets all values from the tag. If any value fails to parse, returns an empty
/// vector.
+#[inline]
fn tag_values(tag: &TagStandard) -> Vec
where
T: FromStr + fmt::Debug,
@@ -113,6 +116,7 @@ where
/// Creates a new NIP-19 nevent string from an event ID and up to 3 unique relay
/// URLs.
+#[inline]
pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result {
Nip19Event::new(event_id)
.relays(
@@ -127,6 +131,7 @@ pub fn new_nevent(event_id: EventId, relays: &[RelayUrl]) -> N34Result {
/// Creates a NIP-19 naddr string for a git repository announcement and up to 3
/// unique relay URLs.
+#[inline]
pub fn repo_naddr(
repo_id: impl Into,
pubk: PublicKey,
@@ -223,6 +228,7 @@ pub fn get_content(
}
/// Path to the `nostr-address` file in current directory.
+#[inline]
pub fn nostr_address_path() -> std::io::Result {
std::env::current_dir().map(|p| p.join(NOSTR_ADDRESS_FILE))
}
@@ -247,6 +253,7 @@ pub fn naddrs_or_file(
/// Generate a reply tag for an event with the given ID, relay URL (if any), and
/// marker.
+#[inline]
pub fn event_reply_tag(reply_to: &EventId, relay: Option<&RelayUrl>, marker: Marker) -> Tag {
Tag::custom(
TagKind::e(),