Skip to content

Commit 2c69974

Browse files
committed
[trace-guest] Optimization to avoid double heap allocation
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 9c6b888 commit 2c69974

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/hyperlight_guest_tracing/src/visitor.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ impl<'a> Visit for FieldsVisitor<'a> {
3434
/// * `value` - The byte slice value
3535
fn record_bytes(&mut self, f: &Field, v: &[u8]) {
3636
let k = String::from(f.name());
37-
let mut val = String::new();
38-
val.push_str(&alloc::format!("{v:?}"));
37+
let val = alloc::format!("{v:?}");
3938
self.out.push(KeyValue { key: k, value: val });
4039
}
4140

@@ -45,8 +44,7 @@ impl<'a> Visit for FieldsVisitor<'a> {
4544
/// * `v` - The string value
4645
fn record_str(&mut self, f: &Field, v: &str) {
4746
let k = String::from(f.name());
48-
let mut val = String::new();
49-
val.push_str(v);
47+
let val = String::from(v);
5048
self.out.push(KeyValue { key: k, value: val });
5149
}
5250

@@ -56,8 +54,7 @@ impl<'a> Visit for FieldsVisitor<'a> {
5654
/// * `v` - The debug value
5755
fn record_debug(&mut self, f: &Field, v: &dyn Debug) {
5856
let k = String::from(f.name());
59-
let mut val = String::new();
60-
val.push_str(&alloc::format!("{v:?}"));
57+
let val = alloc::format!("{v:?}");
6158
self.out.push(KeyValue { key: k, value: val });
6259
}
6360
}

0 commit comments

Comments
 (0)