Skip to content

Commit

Permalink
Replacing imutable strings by SmolStr
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Feb 27, 2025
1 parent d179fd2 commit 52c115a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 98 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lazy_static = "1.4.0"
toml_edit = "0.22.9"
winnow = "0.6.5"
proptest = "1.4.0"
smol_str = {version="0.3.2", features=["serde"]}
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
tracing-opentelemetry = "0.24.0"
Expand Down
6 changes: 4 additions & 2 deletions src/agent/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use {
registry::Registry,
},
serde::Deserialize,
smol_str::SmolStr,
solana_sdk::pubkey::Pubkey,
std::{
net::SocketAddr,
Expand Down Expand Up @@ -113,8 +114,9 @@ impl ProductGlobalMetrics {
metrics
}

pub fn update(&self, product_key: &Pubkey, maybe_symbol: Option<String>) {
let symbol_string = maybe_symbol.unwrap_or(format!("unknown_{}", product_key));
pub fn update(&self, product_key: &Pubkey, maybe_symbol: Option<SmolStr>) {
let symbol_string = maybe_symbol.map(|x| x.into())
.unwrap_or(format!("unknown_{}", product_key));

#[deny(unused_variables)]
let Self { update_count } = self;
Expand Down
15 changes: 8 additions & 7 deletions src/agent/pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use {
},
std::collections::BTreeMap,
std::sync::Arc,
smol_str::SmolStr,
};

pub mod rpc;

pub type Pubkey = String;
pub type Attrs = BTreeMap<String, String>;
pub type Pubkey = SmolStr;
pub type Attrs = BTreeMap<SmolStr, SmolStr>;

pub type Price = i64;
pub type Exponent = i64;
Expand All @@ -27,7 +28,7 @@ pub struct ProductAccountMetadata {
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
pub struct PriceAccountMetadata {
pub account: Pubkey,
pub price_type: String,
pub price_type: SmolStr,
pub price_exponent: Exponent,
}

Expand All @@ -41,9 +42,9 @@ pub struct ProductAccount {
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
pub struct PriceAccount {
pub account: Pubkey,
pub price_type: String,
pub price_type: SmolStr,
pub price_exponent: Exponent,
pub status: String,
pub status: SmolStr,
pub price: Price,
pub conf: Conf,
pub twap: Price,
Expand All @@ -59,7 +60,7 @@ pub struct PriceAccount {
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
pub struct PublisherAccount {
pub account: Pubkey,
pub status: String,
pub status: SmolStr,
pub price: Price,
pub conf: Conf,
pub slot: Slot,
Expand All @@ -82,7 +83,7 @@ pub type SubscriptionID = i64;
pub struct PriceUpdate {
pub price: Price,
pub conf: Conf,
pub status: String,
pub status: SmolStr,
pub valid_slot: Slot,
pub pub_slot: Slot,
}
Loading

0 comments on commit 52c115a

Please sign in to comment.