diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-29 09:39:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-29 09:39:03 -0300 |
commit | 44fab2a44d06a956c3121ceba2b39ca7b00dc428 (patch) | |
tree | 9f492ba2ebaa4fb3cf6554fcb63f3fe026d43a5d /lptree.c | |
parent | 460a35cbcb33fbc56f5a658b96a793b9bb8963e9 (diff) | |
download | lpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.tar.gz lpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.tar.bz2 lpeg-44fab2a44d06a956c3121ceba2b39ca7b00dc428.zip |
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.
Diffstat (limited to 'lptree.c')
-rw-r--r-- | lptree.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -359,7 +359,7 @@ static TTree *newtree (lua_State *L, int len) { | |||
359 | lua_pushvalue(L, -1); | 359 | lua_pushvalue(L, -1); |
360 | lua_setuservalue(L, -3); | 360 | lua_setuservalue(L, -3); |
361 | lua_setmetatable(L, -2); | 361 | lua_setmetatable(L, -2); |
362 | p->code = NULL; p->codesize = 0; | 362 | p->code = NULL; |
363 | return p->tree; | 363 | return p->tree; |
364 | } | 364 | } |
365 | 365 | ||
@@ -1189,7 +1189,7 @@ static Instruction *prepcompile (lua_State *L, Pattern *p, int idx) { | |||
1189 | lua_getuservalue(L, idx); /* push 'ktable' (may be used by 'finalfix') */ | 1189 | lua_getuservalue(L, idx); /* push 'ktable' (may be used by 'finalfix') */ |
1190 | finalfix(L, 0, NULL, p->tree); | 1190 | finalfix(L, 0, NULL, p->tree); |
1191 | lua_pop(L, 1); /* remove 'ktable' */ | 1191 | lua_pop(L, 1); /* remove 'ktable' */ |
1192 | return compile(L, p); | 1192 | return compile(L, p, getsize(L, idx)); |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | 1195 | ||
@@ -1212,7 +1212,7 @@ static int lp_printcode (lua_State *L) { | |||
1212 | printktable(L, 1); | 1212 | printktable(L, 1); |
1213 | if (p->code == NULL) /* not compiled yet? */ | 1213 | if (p->code == NULL) /* not compiled yet? */ |
1214 | prepcompile(L, p, 1); | 1214 | prepcompile(L, p, 1); |
1215 | printpatt(p->code, p->codesize); | 1215 | printpatt(p->code); |
1216 | return 0; | 1216 | return 0; |
1217 | } | 1217 | } |
1218 | 1218 | ||
@@ -1290,7 +1290,7 @@ static int lp_type (lua_State *L) { | |||
1290 | 1290 | ||
1291 | int lp_gc (lua_State *L) { | 1291 | int lp_gc (lua_State *L) { |
1292 | Pattern *p = getpattern(L, 1); | 1292 | Pattern *p = getpattern(L, 1); |
1293 | realloccode(L, p, 0); /* delete code block */ | 1293 | freecode(L, p); /* delete code block */ |
1294 | return 0; | 1294 | return 0; |
1295 | } | 1295 | } |
1296 | 1296 | ||
@@ -1377,7 +1377,6 @@ static struct luaL_Reg metareg[] = { | |||
1377 | 1377 | ||
1378 | int luaopen_lpeg (lua_State *L); | 1378 | int luaopen_lpeg (lua_State *L); |
1379 | int luaopen_lpeg (lua_State *L) { | 1379 | int luaopen_lpeg (lua_State *L) { |
1380 | printf("%ld\n", sizeof(TTree)); | ||
1381 | luaL_newmetatable(L, PATTERN_T); | 1380 | luaL_newmetatable(L, PATTERN_T); |
1382 | lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ | 1381 | lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ |
1383 | lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); | 1382 | lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); |