Permalink
Browse files

optimize: coroutine status string look-up is now a bit more efficient…

… by specifying the string lengths explicitly. thanks Tatsuhiko Kubo for the patch in #338.
  • Loading branch information...
agentzh committed Feb 26, 2014
1 parent eab5694 commit 4a0036c0746e62666e5de27147a6b3c33c8dc7c9
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/ngx_http_lua_coroutine.c
@@ -30,9 +30,15 @@ static int ngx_http_lua_coroutine_yield(lua_State *L);
static int ngx_http_lua_coroutine_status(lua_State *L);
static const char *
static const ngx_str_t
ngx_http_lua_co_status_names[] =
{"running", "suspended", "normal", "dead", "zombie"};
{
ngx_string("running"),
ngx_string("suspended"),
ngx_string("normal"),
ngx_string("dead"),
ngx_string("zombie")
};
@@ -160,7 +166,7 @@ ngx_http_lua_coroutine_resume(lua_State *L)
lua_pushboolean(L, 0);
lua_pushfstring(L, "cannot resume %s coroutine",
ngx_http_lua_co_status_names[coctx->co_status]);
ngx_http_lua_co_status_names[coctx->co_status].data);
return 2;
}
@@ -345,13 +351,17 @@ ngx_http_lua_coroutine_status(lua_State *L)
coctx = ngx_http_lua_get_co_ctx(co, ctx);
if (coctx == NULL) {
lua_pushstring(L, ngx_http_lua_co_status_names[NGX_HTTP_LUA_CO_DEAD]);
lua_pushlstring(L, (const char *)
ngx_http_lua_co_status_names[NGX_HTTP_LUA_CO_DEAD].data,
ngx_http_lua_co_status_names[NGX_HTTP_LUA_CO_DEAD].len);
return 1;
}
dd("co status: %d", coctx->co_status);
lua_pushstring(L, ngx_http_lua_co_status_names[coctx->co_status]);
lua_pushlstring(L, (const char *)
ngx_http_lua_co_status_names[coctx->co_status].data,
ngx_http_lua_co_status_names[coctx->co_status].len);
return 1;
}

0 comments on commit 4a0036c

Please sign in to comment.