From 41c3f628de7a9cec8208607d943ee913ffa659ed Mon Sep 17 00:00:00 2001 From: Xing Tian Date: Fri, 15 Jan 2021 18:04:59 +0800 Subject: [PATCH 1/2] Avoid unnecessary copy value and map.find in lru_cache --- include/boost/compute/detail/lru_cache.hpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/include/boost/compute/detail/lru_cache.hpp b/include/boost/compute/detail/lru_cache.hpp index fe1a56f74..b629835e5 100644 --- a/include/boost/compute/detail/lru_cache.hpp +++ b/include/boost/compute/detail/lru_cache.hpp @@ -75,7 +75,7 @@ class lru_cache // insert the new item m_list.push_front(key); - m_map[key] = std::make_pair(value, m_list.begin()); + m_map.emplace(key, std::make_pair(value, m_list.begin())); } } @@ -97,18 +97,10 @@ class lru_cache m_list.push_front(key); // update iterator in map - j = m_list.begin(); - const value_type &value = i->second.first; - m_map[key] = std::make_pair(value, j); - - // return the value - return value; - } - else { - // the item is already at the front of the most recently - // used list so just return it - return i->second.first; + i->second.second = m_list.begin(); } + // return the value + return i->second.first; } void clear() From d0e7f5aaf7dbbe34f8a51360ec3bb52fbf789b42 Mon Sep 17 00:00:00 2001 From: Xing Tian Date: Fri, 15 Jan 2021 18:08:14 +0800 Subject: [PATCH 2/2] use space --- include/boost/compute/detail/lru_cache.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/compute/detail/lru_cache.hpp b/include/boost/compute/detail/lru_cache.hpp index b629835e5..c89960a40 100644 --- a/include/boost/compute/detail/lru_cache.hpp +++ b/include/boost/compute/detail/lru_cache.hpp @@ -97,7 +97,7 @@ class lru_cache m_list.push_front(key); // update iterator in map - i->second.second = m_list.begin(); + i->second.second = m_list.begin(); } // return the value return i->second.first;