-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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;)Lines 46 to 68 in 3d74939
| 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
Labels
No labels