Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
48c49c48
Commit
48c49c48
authored
May 06, 2014
by
antirez
Browse files
Scripting: cache argv in luaRedisGenericCommand().
~ 4% consistently measured speed improvement.
parent
3318b747
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
48c49c48
...
...
@@ -203,10 +203,13 @@ void luaSortArray(lua_State *lua) {
int
luaRedisGenericCommand
(
lua_State
*
lua
,
int
raise_error
)
{
int
j
,
argc
=
lua_gettop
(
lua
);
struct
redisCommand
*
cmd
;
robj
**
argv
;
redisClient
*
c
=
server
.
lua_client
;
sds
reply
;
/* Cached across calls. */
static
robj
**
argv
=
NULL
;
static
int
argv_size
=
0
;
/* Require at least one argument */
if
(
argc
==
0
)
{
luaPushError
(
lua
,
...
...
@@ -215,7 +218,13 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
}
/* Build the arguments vector */
argv
=
zmalloc
(
sizeof
(
robj
*
)
*
argc
);
if
(
!
argv
)
{
argv
=
zmalloc
(
sizeof
(
robj
*
)
*
argc
);
}
else
if
(
argv_size
<
argc
)
{
argv
=
zrealloc
(
argv
,
sizeof
(
robj
*
)
*
argc
);
argv_size
=
argc
;
}
for
(
j
=
0
;
j
<
argc
;
j
++
)
{
if
(
!
lua_isstring
(
lua
,
j
+
1
))
break
;
argv
[
j
]
=
createStringObject
((
char
*
)
lua_tostring
(
lua
,
j
+
1
),
...
...
@@ -231,7 +240,6 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
decrRefCount
(
argv
[
j
]);
j
--
;
}
zfree
(
argv
);
luaPushError
(
lua
,
"Lua redis() command arguments must be strings or integers"
);
return
1
;
...
...
@@ -339,7 +347,10 @@ cleanup:
* argv/argc of the client instead of the local variables. */
for
(
j
=
0
;
j
<
c
->
argc
;
j
++
)
decrRefCount
(
c
->
argv
[
j
]);
zfree
(
c
->
argv
);
if
(
c
->
argv
!=
argv
)
{
zfree
(
c
->
argv
);
argv
=
NULL
;
}
if
(
raise_error
)
{
/* If we are here we should have an error in the stack, in the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment