Skip to content

Deleting expired objects can be optimized #3

@mkcms

Description

@mkcms

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions