Skip to content

Commit 596a9d6

Browse files
authored
fix: take ExecToolCallOutput by value to avoid clone() (#2197)
Since the output could be a large string, it seemed like a win to avoid the `clone()` in the common case.
1 parent 320f150 commit 596a9d6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

codex-rs/core/src/codex.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ async fn handle_container_exec_with_params(
19811981
let ExecToolCallOutput { exit_code, .. } = &output;
19821982

19831983
let is_success = *exit_code == 0;
1984-
let content = format_exec_output(&output);
1984+
let content = format_exec_output(output);
19851985
ResponseInputItem::FunctionCallOutput {
19861986
call_id: call_id.clone(),
19871987
output: FunctionCallOutputPayload {
@@ -2113,7 +2113,7 @@ async fn handle_sandbox_error(
21132113
let ExecToolCallOutput { exit_code, .. } = &retry_output;
21142114

21152115
let is_success = *exit_code == 0;
2116-
let content = format_exec_output(&retry_output);
2116+
let content = format_exec_output(retry_output);
21172117

21182118
ResponseInputItem::FunctionCallOutput {
21192119
call_id: call_id.clone(),
@@ -2146,7 +2146,7 @@ async fn handle_sandbox_error(
21462146
}
21472147

21482148
/// Exec output is a pre-serialized JSON payload
2149-
fn format_exec_output(exec_output: &ExecToolCallOutput) -> String {
2149+
fn format_exec_output(exec_output: ExecToolCallOutput) -> String {
21502150
let ExecToolCallOutput {
21512151
exit_code,
21522152
stdout,
@@ -2169,10 +2169,10 @@ fn format_exec_output(exec_output: &ExecToolCallOutput) -> String {
21692169
// round to 1 decimal place
21702170
let duration_seconds = ((duration.as_secs_f32()) * 10.0).round() / 10.0;
21712171

2172-
let is_success = *exit_code == 0;
2172+
let is_success = exit_code == 0;
21732173
let output = if is_success { stdout } else { stderr };
21742174

2175-
let mut formatted_output = output.text.clone();
2175+
let mut formatted_output = output.text;
21762176
if let Some(truncated_after_lines) = output.truncated_after_lines {
21772177
formatted_output.push_str(&format!(
21782178
"\n\n[Output truncated after {truncated_after_lines} lines: too many lines or bytes.]",
@@ -2182,7 +2182,7 @@ fn format_exec_output(exec_output: &ExecToolCallOutput) -> String {
21822182
let payload = ExecOutput {
21832183
output: &formatted_output,
21842184
metadata: ExecMetadata {
2185-
exit_code: *exit_code,
2185+
exit_code,
21862186
duration_seconds,
21872187
},
21882188
};

0 commit comments

Comments
 (0)