From 0dfa337ba4d7f530b6be4c4e55de932db603ea63 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 12 Mar 2019 09:54:48 +0100 Subject: [PATCH] Use a single hashmap lookup to determine if a color has been resolved, and to what, instead of two lookups. --- src/backend/curses/n.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 525d304..9575c0d 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -153,12 +153,13 @@ impl Backend { let mut pairs = self.pairs.borrow_mut(); // Find if we have this color in stock - let (front, back) = find_closest_pair(pair); - if pairs.contains_key(&(front, back)) { + let result = find_closest_pair(pair); + let lookup = pairs.get(&result); + if lookup.is_some() { // We got it! - pairs[&(front, back)] + *lookup.unwrap() } else { - self.insert_color(&mut *pairs, (front, back)) + self.insert_color(&mut *pairs, result) } }