From 44fab2a44d06a956c3121ceba2b39ca7b00dc428 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 29 May 2023 09:39:03 -0300 Subject: Code size stored in code itself Most patterns do not have code, as they are not directly used for a match; they are created only to compose larger patterns. So, we shouldn't waste space to store the size of their code, as a NULL pointer already indicates that the size is zero. --- lptree.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lptree.c') diff --git a/lptree.c b/lptree.c index dcee27e..0b2d824 100644 --- a/lptree.c +++ b/lptree.c @@ -359,7 +359,7 @@ static TTree *newtree (lua_State *L, int len) { lua_pushvalue(L, -1); lua_setuservalue(L, -3); lua_setmetatable(L, -2); - p->code = NULL; p->codesize = 0; + p->code = NULL; return p->tree; } @@ -1189,7 +1189,7 @@ static Instruction *prepcompile (lua_State *L, Pattern *p, int idx) { lua_getuservalue(L, idx); /* push 'ktable' (may be used by 'finalfix') */ finalfix(L, 0, NULL, p->tree); lua_pop(L, 1); /* remove 'ktable' */ - return compile(L, p); + return compile(L, p, getsize(L, idx)); } @@ -1212,7 +1212,7 @@ static int lp_printcode (lua_State *L) { printktable(L, 1); if (p->code == NULL) /* not compiled yet? */ prepcompile(L, p, 1); - printpatt(p->code, p->codesize); + printpatt(p->code); return 0; } @@ -1290,7 +1290,7 @@ static int lp_type (lua_State *L) { int lp_gc (lua_State *L) { Pattern *p = getpattern(L, 1); - realloccode(L, p, 0); /* delete code block */ + freecode(L, p); /* delete code block */ return 0; } @@ -1377,7 +1377,6 @@ static struct luaL_Reg metareg[] = { int luaopen_lpeg (lua_State *L); int luaopen_lpeg (lua_State *L) { -printf("%ld\n", sizeof(TTree)); luaL_newmetatable(L, PATTERN_T); lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); -- cgit v1.2.3-55-g6feb