Skip to content

Commit 41c3f62

Browse files
Xing TianXing Tian
authored andcommitted
Avoid unnecessary copy value and map.find in lru_cache
1 parent 36c8913 commit 41c3f62

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

include/boost/compute/detail/lru_cache.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class lru_cache
7575

7676
// insert the new item
7777
m_list.push_front(key);
78-
m_map[key] = std::make_pair(value, m_list.begin());
78+
m_map.emplace(key, std::make_pair(value, m_list.begin()));
7979
}
8080
}
8181

@@ -97,18 +97,10 @@ class lru_cache
9797
m_list.push_front(key);
9898

9999
// update iterator in map
100-
j = m_list.begin();
101-
const value_type &value = i->second.first;
102-
m_map[key] = std::make_pair(value, j);
103-
104-
// return the value
105-
return value;
106-
}
107-
else {
108-
// the item is already at the front of the most recently
109-
// used list so just return it
110-
return i->second.first;
100+
i->second.second = m_list.begin();
111101
}
102+
// return the value
103+
return i->second.first;
112104
}
113105

114106
void clear()

0 commit comments

Comments
 (0)