Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary copy value and map.find in lru_cache #859

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions include/boost/compute/detail/lru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand All @@ -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()
Expand Down