Skip to content

Commit fa4186c

Browse files
committed
avoid extra String allocs for cmd line args
1 parent 9c857a2 commit fa4186c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/volta-core/src/event.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ impl EventLog {
102102

103103
pub fn add_event_start(&mut self, activity_kind: ActivityKind) {
104104
let argv = env::args_os()
105-
.map(|arg| arg.to_string_lossy().to_string())
106-
.collect::<Vec<String>>()
107-
.join(" ");
105+
.enumerate()
106+
.fold(String::new(), |mut result, (i, arg)| {
107+
if i > 0 {
108+
result.push(' ');
109+
}
110+
result.push_str(&arg.to_string_lossy());
111+
result
112+
});
108113
self.add_event(EventKind::Start { argv }, activity_kind)
109114
}
110115
pub fn add_event_end(&mut self, activity_kind: ActivityKind, exit_code: ExitCode) {

0 commit comments

Comments
 (0)