From 9c3e6cb51fb83675a99d09979aa4deeb76f428f5 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 11 Dec 2023 03:53:18 +0200 Subject: [PATCH] perf: use of ok_or followed by a function call --- crates/lib/src/games/jc2m.rs | 2 +- crates/lib/src/protocols/gamespy/common.rs | 2 +- crates/lib/src/protocols/unreal2/protocol.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/lib/src/games/jc2m.rs b/crates/lib/src/games/jc2m.rs index 3ad22b2..52647aa 100644 --- a/crates/lib/src/games/jc2m.rs +++ b/crates/lib/src/games/jc2m.rs @@ -90,7 +90,7 @@ pub fn query_with_timeout( let packets = client.get_server_packets()?; let data = packets .get(0) - .ok_or(PacketBad.context("First packet missing"))?; + .ok_or_else(|| PacketBad.context("First packet missing"))?; let (mut server_vars, remaining_data) = data_to_map(data)?; let players = parse_players_and_teams(&remaining_data)?; diff --git a/crates/lib/src/protocols/gamespy/common.rs b/crates/lib/src/protocols/gamespy/common.rs index 9f78e17..18b672d 100644 --- a/crates/lib/src/protocols/gamespy/common.rs +++ b/crates/lib/src/protocols/gamespy/common.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; pub fn has_password(server_vars: &mut HashMap) -> GDResult { let password_value = server_vars .remove("password") - .ok_or(GDErrorKind::PacketBad.context("Missing password (exists) field"))? + .ok_or_else(|| GDErrorKind::PacketBad.context("Missing password (exists) field"))? .to_lowercase(); if let Ok(has) = password_value.parse::() { diff --git a/crates/lib/src/protocols/unreal2/protocol.rs b/crates/lib/src/protocols/unreal2/protocol.rs index b1326b8..beeed44 100644 --- a/crates/lib/src/protocols/unreal2/protocol.rs +++ b/crates/lib/src/protocols/unreal2/protocol.rs @@ -209,7 +209,7 @@ impl StringDecoder for Unreal2StringDecoder { let mut ucs2 = false; let mut length: usize = (*data .first() - .ok_or(PacketBad.context("Tried to decode string without length"))?) + .ok_or_else(|| PacketBad.context("Tried to decode string without length"))?) .into(); let mut start = 0;