diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-06-17 15:20:27 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-06-17 15:20:27 +0100 |
commit | 63e72fc5d4f6712fb4ad41659f8189500386546d (patch) | |
tree | cbb8e8d5bb47929e80fbb8a34e0a1420c1f099f0 /src/lua | |
parent | dc5d99e5cf918d594f52dfce7c7250eb1da8c766 (diff) | |
download | rspamd-63e72fc5d4f6712fb4ad41659f8189500386546d.tar.gz rspamd-63e72fc5d4f6712fb4ad41659f8189500386546d.zip |
[Minor] Get rid of one more GHashTable
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.h | 5 | ||||
-rw-r--r-- | src/lua/lua_task.c | 30 |
2 files changed, 13 insertions, 22 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 226b250a7..c0c0c37c8 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -139,11 +139,6 @@ struct rspamd_lua_map { } data; }; -struct rspamd_lua_cached_entry { - gint ref; - guint id; -}; - struct rspamd_lua_upstream { struct upstream *up; gint upref; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 1e0e0a147..62bda0522 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1420,27 +1420,24 @@ lua_task_set_cached (lua_State *L, struct rspamd_task *task, const gchar *key, gint pos) { LUA_TRACE_POINT; - struct rspamd_lua_cached_entry *entry; + khiter_t k; lua_pushvalue (L, pos); - entry = g_hash_table_lookup (task->lua_cache, key); + k = kh_get(rspamd_task_lua_cache, &task->lua_cache, (char *)key); - if (G_UNLIKELY (entry != NULL)) { + if (G_UNLIKELY (k != kh_end(&task->lua_cache))) { /* Unref previous value */ - luaL_unref (L, LUA_REGISTRYINDEX, entry->ref); + luaL_unref (L, LUA_REGISTRYINDEX, kh_value(&task->lua_cache, k).ref); } else { - entry = rspamd_mempool_alloc (task->task_pool, sizeof (*entry)); - g_hash_table_insert (task->lua_cache, - rspamd_mempool_strdup (task->task_pool, key), entry); - } - - entry->ref = luaL_ref (L, LUA_REGISTRYINDEX); + int r; - if (task->message) { - entry->id = GPOINTER_TO_UINT (task->message); + k = kh_put(rspamd_task_lua_cache, &task->lua_cache, rspamd_mempool_strdup (task->task_pool, key), &r); } + + kh_value(&task->lua_cache, k).ref = luaL_ref (L, LUA_REGISTRYINDEX); + kh_value(&task->lua_cache, k).id = GPOINTER_TO_UINT (task->message); } @@ -1448,13 +1445,12 @@ static gboolean lua_task_get_cached (lua_State *L, struct rspamd_task *task, const gchar *key) { LUA_TRACE_POINT; - struct rspamd_lua_cached_entry *entry; + khiter_t k; - entry = g_hash_table_lookup (task->lua_cache, key); + k = kh_get(rspamd_task_lua_cache, &task->lua_cache, (char *)key); - if (entry != NULL && (task->message && - entry->id == GPOINTER_TO_UINT (task->message))) { - lua_rawgeti (L, LUA_REGISTRYINDEX, entry->ref); + if (k != kh_end(&task->lua_cache) && (kh_value(&task->lua_cache, k).id == GPOINTER_TO_UINT (task->message))) { + lua_rawgeti (L, LUA_REGISTRYINDEX, kh_value(&task->lua_cache, k).ref); return TRUE; } |