summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-12-21 18:15:14 +0800
committeryangwei <[email protected]>2024-01-08 17:14:57 +0800
commit2696de9a902f42ff527edb88967e22dd4d02448f (patch)
tree5eec6bce9afb629a0292361fc6147a678c42ef9f
parentc7b6d4c7544fc3d9ec74e6bd64e08f454fb33d94 (diff)
🎈 perf(stack allocation of XXH3_state ): reduce heap usage
-rw-r--r--src/tags/my_ut_hash.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/tags/my_ut_hash.c b/src/tags/my_ut_hash.c
index 74a09be..582f0c8 100644
--- a/src/tags/my_ut_hash.c
+++ b/src/tags/my_ut_hash.c
@@ -140,22 +140,21 @@ unsigned int cal_tag_hash_xxhash(const struct fieldstat_tag *tag, size_t n_tag,
XXH128_hash_t cal_tag_hash_xxhash128(const struct fieldstat_tag *tag, size_t n_tag, unsigned int seed)
{
- XXH3_state_t *state = XXH3_createState();
- XXH3_128bits_reset_withSeed(state, seed);
+ XXH3_state_t state;
+ XXH3_128bits_reset_withSeed(&state, seed);
for (int i = 0; i < n_tag; i++)
{
- XXH3_128bits_update(state, tag[i].key, strlen(tag[i].key));
+ XXH3_128bits_update(&state, tag[i].key, strlen(tag[i].key));
if (tag[i].type != TAG_CSTRING) { // sizeof(long long) == sizeof(double)
- XXH3_128bits_update(state, &tag[i].value_longlong, sizeof(long long));
+ XXH3_128bits_update(&state, &tag[i].value_longlong, sizeof(long long));
} else {
- XXH3_128bits_update(state, tag[i].value_str, strlen(tag[i].value_str));
+ XXH3_128bits_update(&state, tag[i].value_str, strlen(tag[i].value_str));
}
}
- XXH128_hash_t ret = XXH3_128bits_digest(state);
- XXH3_freeState(state);
+ XXH128_hash_t ret = XXH3_128bits_digest(&state);
return ret;
}