shared_cache: pass key (K) by const ref in interface methods

Signed-off-by: Somnath Roy <somnath.roy@sandisk.com>
This commit is contained in:
Somnath Roy 2014-06-30 00:24:39 -07:00
parent 95ac43f34c
commit b04d84db8c

View File

@ -43,7 +43,7 @@ class SharedLRU {
}
}
void lru_remove(K key) {
void lru_remove(const K& key) {
typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
contents.find(key);
if (i == contents.end())
@ -53,7 +53,7 @@ class SharedLRU {
contents.erase(i);
}
void lru_add(K key, VPtr val, list<VPtr> *to_release) {
void lru_add(const K& key, const VPtr& val, list<VPtr> *to_release) {
typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
contents.find(key);
if (i != contents.end()) {
@ -66,7 +66,7 @@ class SharedLRU {
}
}
void remove(K key) {
void remove(const K& key) {
Mutex::Locker l(lock);
weak_refs.erase(key);
cond.Signal();
@ -93,7 +93,7 @@ public:
assert(weak_refs.empty());
}
void clear(K key) {
void clear(const K& key) {
VPtr val; // release any ref we have after we drop the lock
{
Mutex::Locker l(lock);
@ -119,7 +119,7 @@ public:
return weak_refs.begin()->first;
}
VPtr lower_bound(K key) {
VPtr lower_bound(const K& key) {
VPtr val;
list<VPtr> to_release;
{
@ -145,7 +145,7 @@ public:
return val;
}
VPtr lookup(K key) {
VPtr lookup(const K& key) {
VPtr val;
list<VPtr> to_release;
{
@ -181,7 +181,7 @@ public:
* map, false otherwise
* @return A reference to the map's value for the given key
*/
VPtr add(K key, V *value, bool *existed = NULL) {
VPtr add(const K& key, V *value, bool *existed = NULL) {
VPtr val(value, Cleanup(this, key));
list<VPtr> to_release;
{