Skip to content

Commit 1e4ba6e

Browse files
committed
Scripting: Use faster API for Lua client c->argv creation.
Replace the three calls to Lua API lua_tostring, lua_lua_strlen, and lua_isstring, with a single call to lua_tolstring. ~ 5% consistent speed gain measured.
1 parent 76fda9f commit 1e4ba6e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/scripting.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
226226
}
227227

228228
for (j = 0; j < argc; j++) {
229-
if (!lua_isstring(lua,j+1)) break;
230-
argv[j] = createStringObject((char*)lua_tostring(lua,j+1),
231-
lua_strlen(lua,j+1));
229+
char *obj_s;
230+
size_t obj_len;
231+
232+
obj_s = (char*)lua_tolstring(lua,j+1,&obj_len);
233+
if (obj_s == NULL) break; /* Not a string. */
234+
argv[j] = createStringObject(obj_s, obj_len);
232235
}
233236

234237
/* Check if one of the arguments passed by the Lua script

0 commit comments

Comments
 (0)