Skip to content

Commit c752049

Browse files
committed
optimize: fixed the initial table sizes for "ngx", "ngx.config", and "ngx.re".
1 parent 9577e5f commit c752049

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

src/ngx_http_lua_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ngx_http_lua_inject_config_api(lua_State *L)
1818
{
1919
/* ngx.config */
2020

21-
lua_newtable(L); /* .config */
21+
lua_createtable(L, 0, 1 /* nrec */); /* .config */
2222

2323
#if (NGX_DEBUG)
2424
lua_pushboolean(L, 1);

src/ngx_http_lua_regex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ ngx_http_lua_inject_regex_api(lua_State *L)
18071807
{
18081808
/* ngx.re */
18091809

1810-
lua_newtable(L); /* .re */
1810+
lua_createtable(L, 0, 4 /* nrec */); /* .re */
18111811

18121812
lua_pushcfunction(L, ngx_http_lua_ngx_re_match);
18131813
lua_setfield(L, -2, "match");

src/ngx_http_lua_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ ngx_http_lua_inject_ngx_api(ngx_conf_t *cf, lua_State *L)
743743

744744
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
745745

746-
lua_createtable(L, 0 /* narr */, 95 /* nrec */); /* ngx.* */
746+
lua_createtable(L, 0 /* narr */, 96 /* nrec */); /* ngx.* */
747747

748748
ngx_http_lua_inject_arg_api(L);
749749

t/062-count.t

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ __DATA__
3535
--- request
3636
GET /test
3737
--- response_body
38-
ngx: 95
38+
ngx: 96
3939
--- no_error_log
4040
[error]
4141
@@ -56,7 +56,7 @@ ngx: 95
5656
--- request
5757
GET /test
5858
--- response_body
59-
95
59+
96
6060
--- no_error_log
6161
[error]
6262
@@ -84,7 +84,7 @@ GET /test
8484
--- request
8585
GET /test
8686
--- response_body
87-
n = 95
87+
n = 96
8888
--- no_error_log
8989
[error]
9090
@@ -301,7 +301,7 @@ GET /t
301301
--- response_body_like: 404 Not Found
302302
--- error_code: 404
303303
--- error_log
304-
ngx. entry count: 95
304+
ngx. entry count: 96
305305
306306
307307
@@ -323,3 +323,43 @@ n = 1
323323
--- no_error_log
324324
[error]
325325
326+
327+
328+
=== TEST 15: entries under ngx.config
329+
--- config
330+
location = /test {
331+
content_by_lua '
332+
local n = 0
333+
for k, v in pairs(ngx.config) do
334+
n = n + 1
335+
end
336+
ngx.say("n = ", n)
337+
';
338+
}
339+
--- request
340+
GET /test
341+
--- response_body
342+
n = 1
343+
--- no_error_log
344+
[error]
345+
346+
347+
348+
=== TEST 16: entries under ngx.re
349+
--- config
350+
location = /test {
351+
content_by_lua '
352+
local n = 0
353+
for k, v in pairs(ngx.re) do
354+
n = n + 1
355+
end
356+
ngx.say("n = ", n)
357+
';
358+
}
359+
--- request
360+
GET /test
361+
--- response_body
362+
n = 4
363+
--- no_error_log
364+
[error]
365+

0 commit comments

Comments
 (0)