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

Deleting expired objects can be optimized #3

Open
mkcms opened this issue Jun 6, 2020 · 0 comments
Open

Deleting expired objects can be optimized #3

mkcms opened this issue Jun 6, 2020 · 0 comments

Comments

@mkcms
Copy link
Contributor

mkcms commented Jun 6, 2020

This function can clearly be optimized, once we have enough memory to store something we can exit the loop. IOW, the loop condition should be:

for (auto it = stored_map.begin(); it != stored_map.end() && !have_enough_memory_to_store_whatever_called_me;)

template <typename T>
int delete_expired_objects(uint32_t timestamp, uint32_t expire_time,
T& stored_map, nf9_stats& stats)
{
int deleted_objects = 0;
uint32_t expiration_timestamp;
if (timestamp > expire_time)
expiration_timestamp = timestamp - expire_time;
else
expiration_timestamp = 0;
for (auto it = stored_map.begin(); it != stored_map.end();) {
if (it->second.timestamp <= expiration_timestamp) {
++deleted_objects;
++stats.expired_templates;
it = stored_map.erase(it);
}
else {
++it;
}
}
return deleted_objects;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant