From e891c9546aa997ef84a8bf5513c745eb9d34c8e0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 19 Oct 2021 17:53:20 +0100 Subject: [PATCH] [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); -- 2.39.5