diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a739134..baa71f471 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ * nostr: update `PartialEvent` methods ([Yuki Kishimoto]) * nostr: change `EventBuilder::award_badge` fingerprint ([Yuki Kishimoto]) * nostr: add NIP-50 support to `Filter::match_event` method ([Yuki Kishimoto]) +* nostr: remove `Arc` from `OnceCell` in `Event` and `Tag` ([Yuki Kishimoto]) * pool: take mutex ownership instead of clone in `InternalRelayPool::get_events_from` ([Yuki Kishimoto]) * pool: remove IDs collection from `InternalRelayPool::get_events_from` ([Yuki Kishimoto]) * pool: better checks before perform queries or send messages to relays ([Yuki Kishimoto]) diff --git a/crates/nostr/src/event/mod.rs b/crates/nostr/src/event/mod.rs index f4ced59ca..cec44f980 100644 --- a/crates/nostr/src/event/mod.rs +++ b/crates/nostr/src/event/mod.rs @@ -7,8 +7,6 @@ use alloc::collections::{BTreeMap, BTreeSet}; use alloc::string::{String, ToString}; -#[cfg(feature = "std")] -use alloc::sync::Arc; use alloc::vec::Vec; use core::cmp::Ordering; use core::fmt; @@ -137,7 +135,7 @@ pub struct Event { deser_order: Vec, /// Tags indexes #[cfg(feature = "std")] - tags_indexes: Arc>, + tags_indexes: OnceCell, } impl fmt::Debug for Event { @@ -215,7 +213,7 @@ impl Event { }, deser_order: Vec::new(), #[cfg(feature = "std")] - tags_indexes: Arc::new(OnceCell::new()), + tags_indexes: OnceCell::new(), } } @@ -653,7 +651,7 @@ impl<'de> Deserialize<'de> for Event { inner: serde_json::from_value(value).map_err(serde::de::Error::custom)?, deser_order, #[cfg(feature = "std")] - tags_indexes: Arc::new(OnceCell::new()), + tags_indexes: OnceCell::new(), }) } } diff --git a/crates/nostr/src/event/tag/mod.rs b/crates/nostr/src/event/tag/mod.rs index ff78a1c19..bc7c2c2eb 100644 --- a/crates/nostr/src/event/tag/mod.rs +++ b/crates/nostr/src/event/tag/mod.rs @@ -5,7 +5,6 @@ //! Tag use alloc::string::{String, ToString}; -use alloc::sync::Arc; use alloc::vec::Vec; use core::cmp::Ordering; use core::hash::{Hash, Hasher}; @@ -37,7 +36,7 @@ use crate::{ImageDimensions, PublicKey, SingleLetterTag, Timestamp, UncheckedUrl #[derive(Debug, Clone)] pub struct Tag { buf: Vec, - standardized: Arc>>, + standardized: OnceCell>, } impl PartialEq for Tag { @@ -71,7 +70,7 @@ impl Tag { fn new(buf: Vec, standardized: Option) -> Self { Self { buf, - standardized: Arc::new(OnceCell::from(standardized)), + standardized: OnceCell::from(standardized), } } @@ -79,7 +78,7 @@ impl Tag { fn new_with_empty_cell(buf: Vec) -> Self { Self { buf, - standardized: Arc::new(OnceCell::new()), + standardized: OnceCell::new(), } } @@ -146,10 +145,7 @@ impl Tag { /// Consume tag and get standardized tag pub fn to_standardized(self) -> Option { - // TODO: replace with `Arc::unwrap_or_clone(self.standardized)` when MSRV will be >= 1.76.0 - let standardized: OnceCell> = - Arc::try_unwrap(self.standardized).unwrap_or_else(|arc| (*arc).clone()); - match standardized.into_inner() { + match self.standardized.into_inner() { Some(inner) => inner, None => TagStandard::parse(&self.buf).ok(), }