From: Jason Ish Date: Fri, 20 Aug 2021 16:59:41 +0000 (-0600) Subject: rust(lint): don't use unwrap_or for function calls X-Git-Tag: suricata-7.0.0-beta1~1522 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bf5de335065ffd45507f08312cdb69ab190d004;p=thirdparty%2Fsuricata.git rust(lint): don't use unwrap_or for function calls Calling a function in unwrap_or causes that function to always be called even when not needed. Instead use unwrap_or_else with a closure which will only be called when needed. --- diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 3f00e8312b..45b68a66d0 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -2149,7 +2149,7 @@ mod tests { .zip(expected_uuid) .map(|(x, y)| x.cmp(y)) .find(|&ord| ord != cmp::Ordering::Equal) - .unwrap_or(bind_uuid.len().cmp(&expected_uuid.len())) + .unwrap_or_else(|| bind_uuid.len().cmp(&expected_uuid.len())) ); } } diff --git a/rust/src/smb/smb1_records.rs b/rust/src/smb/smb1_records.rs index ec8f1f3052..5bc886532b 100644 --- a/rust/src/smb/smb1_records.rs +++ b/rust/src/smb/smb1_records.rs @@ -582,7 +582,7 @@ pub fn parse_smb_create_andx_request_record<'a>(i: &'a[u8], r: &SmbRecord) >> (SmbRequestCreateAndXRecord { disposition: disposition, create_options: create_options, - file_name: file_name.unwrap_or(Vec::new()), + file_name: file_name.unwrap_or_default(), })) }