pub struct StringPool { /* private fields */ }Expand description
String pool for deduplicating commonly repeated strings in execution history.
Phase names and agent names are repeated frequently across execution history
entries. Using Arc
§Example
use ralph_workflow::checkpoint::string_pool::StringPool;
use std::sync::Arc;
let (pool, phase1) = StringPool::new().intern("Development");
let (_, phase2) = pool.intern("Development");
// Both Arc<str> values point to the same allocation
assert!(Arc::ptr_eq(&phase1, &phase2));Implementations§
Source§impl StringPool
impl StringPool
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new string pool with default capacity hint.
Pre-allocates capacity for 16 unique strings, which is typical for most pipeline runs (phase names, agent names, step types).
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a string pool with specific capacity.
Use this when you know the expected number of unique strings to avoid hash table resizing during initial population.
Sourcepub fn intern_str(self, s: &str) -> (Self, Arc<str>)
pub fn intern_str(self, s: &str) -> (Self, Arc<str>)
Get or insert a string slice into the pool, returning an Arc
Prefer this when the input is already a &str to avoid allocating a
temporary String on repeated calls.
§Example
use ralph_workflow::checkpoint::string_pool::StringPool;
let (pool, s1) = StringPool::new().intern_str("test");
let (pool, s2) = pool.intern_str("test");
assert!(std::sync::Arc::ptr_eq(&s1, &s2));Sourcepub fn intern_string(self, s: String) -> (Self, Arc<str>)
pub fn intern_string(self, s: String) -> (Self, Arc<str>)
Get or insert an owned string into the pool, returning an Arc
This path can reuse the allocation of the provided String when inserting.
Trait Implementations§
Source§impl Clone for StringPool
impl Clone for StringPool
Source§fn clone(&self) -> StringPool
fn clone(&self) -> StringPool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StringPool
impl Debug for StringPool
Source§impl Default for StringPool
impl Default for StringPool
Source§fn default() -> StringPool
fn default() -> StringPool
Auto Trait Implementations§
impl Freeze for StringPool
impl RefUnwindSafe for StringPool
impl Send for StringPool
impl Sync for StringPool
impl Unpin for StringPool
impl UnsafeUnpin for StringPool
impl UnwindSafe for StringPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more