From cd44da15774e25c1b2062b8e34e9096992000ff7 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Wed, 26 Jun 2024 07:39:15 -0400 Subject: [PATCH] implement clippy collapsible if else suggestion; microoptimize temp_val assignment --- src/util.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/util.rs b/src/util.rs index b72dd4e2d..a2e48e0b7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1719,12 +1719,10 @@ pub fn write_json( .map(|(col_idx, b)| { if no_headers { col_idx.to_string() + } else if let Ok(val) = simdutf8::basic::from_utf8(b) { + val.to_owned() } else { - if let Ok(val) = simdutf8::basic::from_utf8(b) { - val.to_owned() - } else { - String::from_utf8_lossy(b).to_string() - } + String::from_utf8_lossy(b).to_string() } }) .collect(); @@ -1747,11 +1745,11 @@ pub fn write_json( } write!(json_wtr, "{{")?; for (idx, b) in record.iter().enumerate() { - if let Ok(val) = simdutf8::basic::from_utf8(b) { - temp_val = val.to_owned(); + temp_val = if let Ok(val) = simdutf8::basic::from_utf8(b) { + val.to_owned() } else { - temp_val = String::from_utf8_lossy(b).to_string(); - } + String::from_utf8_lossy(b).to_string() + }; if temp_val.is_empty() { temp_val.clone_from(&null_val); } else {