From d4dca9187e83dde29be8d76ca50ff53d14199ce9 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 14 Aug 2019 08:44:21 -0400 Subject: [PATCH] Slight speep up fetching the endgame table Replace calls to count(key) + operator[key] with a single call to find(key). Replace the std::map with std::unordered_map which provide O(1) access, although the map has a really small number of objects. Test with [0..4] failed yellow: TC 10+0.1 SPRT elo0: 0.00 alpha: 0.05 elo1: 4.00 beta: 0.05 LLR -2.96 [-2.94,2.94] (rejected) Elo 1.01 [-0.87,3.08] (95%) LOS 85.3% Games 71860 [w:22.3%, l:22.2%, d:55.5%] http://tests.stockfishchess.org/tests/view/5d5432210ebc5925cf109d61 Closes https://github.com/official-stockfish/Stockfish/pull/2269 No functional change --- src/endgame.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/endgame.h b/src/endgame.h index d0a5a97e..e29f8777 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -21,7 +21,7 @@ #ifndef ENDGAME_H_INCLUDED #define ENDGAME_H_INCLUDED -#include +#include #include #include #include @@ -98,7 +98,7 @@ struct Endgame : public EndgameBase { namespace Endgames { template using Ptr = std::unique_ptr>; - template using Map = std::map>; + template using Map = std::unordered_map>; extern std::pair, Map> maps; @@ -119,7 +119,8 @@ namespace Endgames { template const EndgameBase* probe(Key key) { - return map().count(key) ? map()[key].get() : nullptr; + auto it = map().find(key); + return it != map().end() ? it->second.get() : nullptr; } } -- 2.39.2