commit e891c95: [Minor] Lua_cdb: Avoid extra copy on lookup
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Oct 19 19:56:06 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-10-19 17:53:20 +0100
URL: https://github.com/rspamd/rspamd/commit/e891c9546aa997ef84a8bf5513c745eb9d34c8e0
[Minor] Lua_cdb: Avoid extra copy on lookup
---
src/lua/lua_cdb.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c
index 91f770cb3..37f35d985 100644
--- a/src/lua/lua_cdb.c
+++ b/src/lua/lua_cdb.c
@@ -149,9 +149,6 @@ lua_cdb_lookup (lua_State *L)
struct cdb *cdb = lua_check_cdb (L, 1);
gsize klen;
const gchar *what = luaL_checklstring(L, 2, &klen);
- gchar *value;
- gsize vlen;
- gint64 vpos;
if (!cdb || what == NULL) {
return lua_error (L);
@@ -159,12 +156,7 @@ lua_cdb_lookup (lua_State *L)
if (cdb_find (cdb, what, klen) > 0) {
/* Extract and push value to lua as string */
- vpos = cdb_datapos (cdb);
- vlen = cdb_datalen (cdb);
- value = g_malloc (vlen);
- cdb_read (cdb, value, vlen, vpos);
- lua_pushlstring (L, value, vlen);
- g_free (value);
+ lua_pushlstring (L, cdb_getdata (cdb), cdb_datalen (cdb));
}
else {
lua_pushnil (L);
More information about the Commits
mailing list