Skip to content

Commit 7c4dcdf

Browse files
committed
Changed 'euqal_range()' + loop by 'find()' in resolveFirst() methods
1 parent 625f9a5 commit 7c4dcdf

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/anchored_set_variable.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ void AnchoredSetVariable::resolve(const std::string &key,
109109

110110
std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
111111
const std::string &key) {
112-
auto range = equal_range(key);
113-
for (auto it = range.first; it != range.second; ++it) {
114-
std::unique_ptr<std::string> b(new std::string());
115-
b->assign(it->second->getValue());
112+
113+
if (auto search = this->find(key); search != this->end()) {
114+
auto b = std::make_unique<std::string>();
115+
b->assign(search->second->getValue());
116116
return b;
117117
}
118+
118119
return nullptr;
119120
}
120121

src/collection/backend/in_memory-per_process.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ bool InMemoryPerProcess::storeOrUpdateFirst(const std::string &key,
6767
bool InMemoryPerProcess::updateFirst(const std::string &key,
6868
const std::string &value) {
6969
pthread_mutex_lock(&m_lock);
70-
auto range = this->equal_range(key);
7170

72-
for (auto it = range.first; it != range.second; ++it) {
73-
it->second.setValue(value);
71+
if (auto search = this->find(key); search != this->end()) {
72+
search->second.setValue(value);
7473
pthread_mutex_unlock(&m_lock);
7574
return true;
7675
}
76+
7777
pthread_mutex_unlock(&m_lock);
7878
return false;
7979
}
@@ -97,11 +97,11 @@ void InMemoryPerProcess::delIfExpired(const std::string& key) {
9797

9898
void InMemoryPerProcess::setExpiry(const std::string& key, int32_t expiry_seconds) {
9999
pthread_mutex_lock(&m_lock);
100-
auto range = this->equal_range(key);
101-
for (auto it = range.first; it != range.second; ++it) {
102-
it->second.setExpiry(expiry_seconds);
100+
101+
if (auto search = this->find(key); search != this->end()) {
102+
search->second.setExpiry(expiry_seconds);
103103
pthread_mutex_unlock(&m_lock);
104-
return;
104+
return;
105105
}
106106

107107
// We allow an expiry value to be set for a key that has not (yet) had a value set.

0 commit comments

Comments
 (0)