From c72f5819c7f468b026a73b463d198af4051dac3e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 12 May 2018 17:42:07 +0200 Subject: [PATCH] message: Optimise slightly the get_best method. --- src/message.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/message.rs b/src/message.rs index 6bbab781..ffd8f219 100644 --- a/src/message.rs +++ b/src/message.rs @@ -152,12 +152,12 @@ impl Message { return None; } for lang in preferred_langs { - if map.contains_key(lang) { - return Some((Lang::from(lang), &map[lang])); + if let Some(body) = map.get(lang) { + return Some((Lang::from(lang), body)); } } - if map.contains_key("") { - return Some((Lang::new(), &map[""])); + if let Some(body) = map.get("") { + return Some((Lang::new(), body)); } map.iter().map(|(lang, body)| (lang.clone(), body)).next() }