Skip to content

Commit

Permalink
[profiling] Use Box<[ValueType]> instead of Vec<ValueType> (#455)
Browse files Browse the repository at this point in the history
* Use Option<Box<[T]>> instead of Vec<T>

* use None when possible and 0

* don't panic when it's empty

* Use Boxed slice

* use into_iter as it was before

* revert to use iter
  • Loading branch information
taegyunkim authored May 28, 2024
1 parent d8a3c9a commit b462829
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions profiling/src/internal/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Profile {
mappings: FxIndexSet<Mapping>,
observations: Observations,
period: Option<(i64, ValueType)>,
sample_types: Vec<ValueType>,
sample_types: Box<[ValueType]>,
stack_traces: FxIndexSet<StackTrace>,
start_time: SystemTime,
strings: StringTable,
Expand Down Expand Up @@ -243,7 +243,7 @@ impl Profile {
//
// In this case, we use `sample_types` during upscaling of `samples`,
// so we must serialize `Sample` before `SampleType`.
for sample_type in self.sample_types.into_iter() {
for sample_type in self.sample_types.iter() {
let item: pprof::ValueType = sample_type.into();
encoder.encode(ProfileSampleTypesEntry::from(item))?;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Profile {
mappings: Default::default(),
observations: Default::default(),
period: None,
sample_types: vec![],
sample_types: Box::new([]),
stack_traces: Default::default(),
start_time,
strings: Default::default(),
Expand All @@ -453,7 +453,7 @@ impl Profile {
// as immutable" by moving it out, borrowing it, and putting it back.
let owned_sample_types = profile.owned_sample_types.take();
profile.sample_types = match &owned_sample_types {
None => Vec::new(),
None => Box::new([]),
Some(sample_types) => sample_types
.iter()
.map(|sample_type| ValueType {
Expand Down Expand Up @@ -811,7 +811,7 @@ mod api_tests {
assert!(!profile.locations.is_empty());
assert!(!profile.mappings.is_empty());
assert!(!profile.observations.is_empty());
assert!(!profile.sample_types.is_empty());
assert!(!profile.sample_types.as_ref().is_empty());
assert!(profile.period.is_none());
assert!(profile.endpoints.mappings.is_empty());
assert!(profile.endpoints.stats.is_empty());
Expand Down

0 comments on commit b462829

Please sign in to comment.