From a6ae4912368a66939c3f1c3866a9ac2475666f94 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:49:15 -0500 Subject: [PATCH] `python`: micro-optimizations --- src/cmd/python.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cmd/python.rs b/src/cmd/python.rs index 37c17a2ba..4991af5c1 100644 --- a/src/cmd/python.rs +++ b/src/cmd/python.rs @@ -209,8 +209,9 @@ pub fn run(argv: &[&str]) -> CliResult<()> { if rconfig.no_headers { headers = csv::StringRecord::new(); + let mut buffer = itoa::Buffer::new(); for i in 0..headers_len { - headers.push_field(&i.to_string()); + headers.push_field(buffer.format(i)); } } else { if !args.cmd_filter { @@ -305,6 +306,8 @@ pub fn run(argv: &[&str]) -> CliResult<()> { // Initializing locals let mut row_data: Vec<&str> = Vec::with_capacity(headers_len); + // assert so the record.get() below skips bounds check + assert!(record.len() == headers_len); header_vec .iter() .enumerate() @@ -329,7 +332,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { } "Evaluation of given expression failed with the above error!" }) - .unwrap_or(error_result); + .unwrap_or_else(|_| error_result); if args.cmd_map { let result = helpers