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

fix: Changed 'equal_range()' + loop by 'find()' in resolveFirst() methods #3117

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions src/anchored_set_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ 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());

if (auto search = this->find(key); search != this->end()) {
auto b = std::make_unique<std::string>();
b->assign(search->second->getValue());
return b;
airween marked this conversation as resolved.
Show resolved Hide resolved
}

return nullptr;
}

Expand Down
14 changes: 7 additions & 7 deletions src/collection/backend/in_memory-per_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down
Loading