Skip to content

Commit a286b7b

Browse files
committed
LruCache, refactor: use result of insert to check the element in map.
1 parent d27eb00 commit a286b7b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fibjs/src/util/LruCache.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ result_t LruCache::get(exlib::string name, v8::Local<v8::Function> updater,
118118
return CALL_E_JAVASCRIPT;
119119

120120
if (!IsEmpty(v)) {
121-
find = m_datas.find(sname);
122-
if (find == m_datas.end()) {
123-
find = m_datas.insert(std::pair<exlib::string, _linkedNode>(sname, newNode)).first;
121+
std::pair<std::map<exlib::string, _linkedNode>::iterator, bool> ret;
122+
ret = m_datas.insert(std::pair<exlib::string, _linkedNode>(sname, newNode));
123+
if (ret.second) {
124+
find = ret.first;
124125
insert(find);
125126

126127
find->second.insert.now();

0 commit comments

Comments
 (0)