Skip to content

Commit 52c115a

Browse files
committed
Replacing imutable strings by SmolStr
1 parent d179fd2 commit 52c115a

File tree

8 files changed

+117
-98
lines changed

8 files changed

+117
-98
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ lazy_static = "1.4.0"
4646
toml_edit = "0.22.9"
4747
winnow = "0.6.5"
4848
proptest = "1.4.0"
49+
smol_str = {version="0.3.2", features=["serde"]}
4950
tracing = { version = "0.1.40", features = ["log"] }
5051
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
5152
tracing-opentelemetry = "0.24.0"

src/agent/metrics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use {
1515
registry::Registry,
1616
},
1717
serde::Deserialize,
18+
smol_str::SmolStr,
1819
solana_sdk::pubkey::Pubkey,
1920
std::{
2021
net::SocketAddr,
@@ -113,8 +114,9 @@ impl ProductGlobalMetrics {
113114
metrics
114115
}
115116

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

119121
#[deny(unused_variables)]
120122
let Self { update_count } = self;

src/agent/pyth.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use {
55
},
66
std::collections::BTreeMap,
77
std::sync::Arc,
8+
smol_str::SmolStr,
89
};
910

1011
pub mod rpc;
1112

12-
pub type Pubkey = String;
13-
pub type Attrs = BTreeMap<String, String>;
13+
pub type Pubkey = SmolStr;
14+
pub type Attrs = BTreeMap<SmolStr, SmolStr>;
1415

1516
pub type Price = i64;
1617
pub type Exponent = i64;
@@ -27,7 +28,7 @@ pub struct ProductAccountMetadata {
2728
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
2829
pub struct PriceAccountMetadata {
2930
pub account: Pubkey,
30-
pub price_type: String,
31+
pub price_type: SmolStr,
3132
pub price_exponent: Exponent,
3233
}
3334

@@ -41,9 +42,9 @@ pub struct ProductAccount {
4142
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
4243
pub struct PriceAccount {
4344
pub account: Pubkey,
44-
pub price_type: String,
45+
pub price_type: SmolStr,
4546
pub price_exponent: Exponent,
46-
pub status: String,
47+
pub status: SmolStr,
4748
pub price: Price,
4849
pub conf: Conf,
4950
pub twap: Price,
@@ -59,7 +60,7 @@ pub struct PriceAccount {
5960
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
6061
pub struct PublisherAccount {
6162
pub account: Pubkey,
62-
pub status: String,
63+
pub status: SmolStr,
6364
pub price: Price,
6465
pub conf: Conf,
6566
pub slot: Slot,
@@ -82,7 +83,7 @@ pub type SubscriptionID = i64;
8283
pub struct PriceUpdate {
8384
pub price: Price,
8485
pub conf: Conf,
85-
pub status: String,
86+
pub status: SmolStr,
8687
pub valid_slot: Slot,
8788
pub pub_slot: Slot,
8889
}

0 commit comments

Comments
 (0)