Skip to content

Commit 4b38435

Browse files
authored
Merge pull request #3117 from airween/v3/eualrangebyfind
fix: Changed 'equal_range()' + loop by 'find()' in resolveFirst() methods
2 parents adba86e + 16d0df0 commit 4b38435

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/anchored_set_variable.cc

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

100100
std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
101101
const std::string &key) {
102-
auto range = equal_range(key);
103-
for (auto it = range.first; it != range.second; ++it) {
104-
std::unique_ptr<std::string> b(new std::string());
105-
b->assign(it->second->getValue());
106-
return b;
102+
103+
if (auto search = this->find(key); search != this->end()) {
104+
return std::make_unique<std::string>(search->second->getValue());
107105
}
106+
108107
return nullptr;
109108
}
110109

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)