Skip to content

Commit 102a48f

Browse files
authored
Merge pull request #138 from wesleywiser/multiple_args
Add a way to create an `EventId` with multiple arguments
2 parents 6792001 + 82e76d4 commit 102a48f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

measureme/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ repository = "https://github.com/rust-lang/measureme"
1313
travis-ci = { repository = "rust-lang/measureme" }
1414

1515
[dependencies]
16-
rustc-hash = "1.0.1"
1716
parking_lot = "0.11.0"
17+
rustc-hash = "1.0.1"
18+
smallvec = "1.0"

measureme/src/event_id.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use smallvec::SmallVec;
2+
13
use crate::{Profiler, StringComponent, StringId};
24

35
/// Event IDs are strings conforming to the following grammar:
@@ -78,4 +80,18 @@ impl<'p> EventIdBuilder<'p> {
7880
StringComponent::Ref(arg),
7981
]))
8082
}
83+
84+
pub fn from_label_and_args(&self, label: StringId, args: &[StringId]) -> EventId {
85+
// Store up to 7 components on the stack: 1 label + 3 arguments + 3 argument separators
86+
let mut parts = SmallVec::<[StringComponent; 7]>::with_capacity(1 + args.len() * 2);
87+
88+
parts.push(StringComponent::Ref(label));
89+
90+
for arg in args {
91+
parts.push(StringComponent::Value(SEPARATOR_BYTE));
92+
parts.push(StringComponent::Ref(*arg));
93+
}
94+
95+
EventId(self.profiler.alloc_string(&parts[..]))
96+
}
8197
}

0 commit comments

Comments
 (0)