Merge pull request #3117 from airween/v3/eualrangebyfind

fix: Changed 'equal_range()' + loop by 'find()' in resolveFirst() methods
This commit is contained in:
Ervin Hegedus 2024-07-31 15:46:54 +02:00 committed by GitHub
commit 4b38435a6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 12 deletions

View File

@ -99,12 +99,11 @@ void AnchoredSetVariable::resolve(const std::string &key,
std::unique_ptr<std::string> AnchoredSetVariable::resolveFirst(
const std::string &key) {
auto range = equal_range(key);
for (auto it = range.first; it != range.second; ++it) {
std::unique_ptr<std::string> b(new std::string());
b->assign(it->second->getValue());
return b;
if (auto search = this->find(key); search != this->end()) {
return std::make_unique<std::string>(search->second->getValue());
}
return nullptr;
}

View File

@ -67,13 +67,13 @@ bool InMemoryPerProcess::storeOrUpdateFirst(const std::string &key,
bool InMemoryPerProcess::updateFirst(const std::string &key,
const std::string &value) {
pthread_mutex_lock(&m_lock);
auto range = this->equal_range(key);
for (auto it = range.first; it != range.second; ++it) {
it->second.setValue(value);
if (auto search = this->find(key); search != this->end()) {
search->second.setValue(value);
pthread_mutex_unlock(&m_lock);
return true;
}
pthread_mutex_unlock(&m_lock);
return false;
}
@ -97,11 +97,11 @@ void InMemoryPerProcess::delIfExpired(const std::string& key) {
void InMemoryPerProcess::setExpiry(const std::string& key, int32_t expiry_seconds) {
pthread_mutex_lock(&m_lock);
auto range = this->equal_range(key);
for (auto it = range.first; it != range.second; ++it) {
it->second.setExpiry(expiry_seconds);
if (auto search = this->find(key); search != this->end()) {
search->second.setExpiry(expiry_seconds);
pthread_mutex_unlock(&m_lock);
return;
return;
}
// We allow an expiry value to be set for a key that has not (yet) had a value set.