diff options
| author | chenzizhan <[email protected]> | 2024-02-21 18:15:32 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2024-02-21 18:21:59 +0800 |
| commit | 0e7cb56cbc2c67ad5aeb9ae2a8a0eb638220fbae (patch) | |
| tree | 7340dcb7ad57123c86c6b6f6dd13b185c9314db7 | |
| parent | 0d245f733fb9f32772d02246914c951068fa3fc0 (diff) | |
performance: memset calls from maximum length to the actual effective length
| -rw-r--r-- | src/tags/cell_manager.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/tags/cell_manager.c b/src/tags/cell_manager.c index d3601ac..d5f86c0 100644 --- a/src/tags/cell_manager.c +++ b/src/tags/cell_manager.c @@ -84,7 +84,7 @@ void cell_manager_reset(struct cell_manager *pthis) pthis->next_cell_id = 0; pthis->max_cell_id = -1; pthis->current_cell_num = 0; - memset(pthis->id_tag_array, 0, sizeof(struct tag_hash_key *) * pthis->id_tag_array_len); + memset(pthis->id_tag_array, 0, sizeof(struct tag_hash_key *) * (pthis->max_cell_id + 1)); if (pthis->sampling_mode == SAMPLING_MODE_TOPK) { heavy_keeper_reset(pthis->topk_tag_id_map); @@ -132,7 +132,7 @@ void cell_manager_id_tag_array_add(struct cell_manager *pthis, int cell_id, stru struct tag_hash_key **new_array = (struct tag_hash_key **)calloc(new_len, sizeof(struct tag_hash_key *)); assert(new_array != NULL); - memcpy(new_array, pthis->id_tag_array, sizeof(struct tag_hash_key *) * pthis->id_tag_array_len); + memcpy(new_array, pthis->id_tag_array, sizeof(struct tag_hash_key *) * (pthis->max_cell_id + 1)); free(pthis->id_tag_array); pthis->id_tag_array = new_array; pthis->id_tag_array_len = new_len; @@ -313,7 +313,7 @@ void cell_manager_merge_topk(struct cell_manager *dest, const struct cell_manage heavy_keeper_merge_recording_id_details(dest->topk_tag_id_map, src->topk_tag_id_map, cell_id_popped, n_cell_id_popped, cell_id_old, cell_id_added, n_cell_id_added); - memset(dest->id_tag_array, 0, sizeof(struct tag_hash_key *) * dest->id_tag_array_len); + memset(dest->id_tag_array, 0, sizeof(struct tag_hash_key *) * (dest->max_cell_id+1)); struct heavy_keeper_result *result = heavy_keeper_query(dest->topk_tag_id_map); for (size_t i = 0; i < result->n_key; i++) { cell_manager_id_tag_array_add(dest, result->cell_id[i], result->tags[i]); |
