diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-07 15:41:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-07 15:41:01 -0300 |
commit | cf1705c1d96b549ef5887a2bc3038dbc31912e50 (patch) | |
tree | 98d37b61c4f095b089fa40e55032e0479932be6c /lpvm.c | |
parent | e31e13f59ef1a4df1698b15ff1fe0198553cc3c2 (diff) | |
download | lpeg-cf1705c1d96b549ef5887a2bc3038dbc31912e50.tar.gz lpeg-cf1705c1d96b549ef5887a2bc3038dbc31912e50.tar.bz2 lpeg-cf1705c1d96b549ef5887a2bc3038dbc31912e50.zip |
Captures point to string positions using indices
That uses 4 bytes (uint) instead of 8 (char*); the size of the
structure 'Capture' reduces from 16 to 8 bytes in 64-bit machines.
Diffstat (limited to 'lpvm.c')
-rw-r--r-- | lpvm.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -169,7 +169,7 @@ static int resdyncaptures (lua_State *L, int fr, int curr, int limit) { | |||
169 | ** value, 'n' is the number of values (at least 1). The open group | 169 | ** value, 'n' is the number of values (at least 1). The open group |
170 | ** capture is already in 'capture', before the place for the new entries. | 170 | ** capture is already in 'capture', before the place for the new entries. |
171 | */ | 171 | */ |
172 | static void adddyncaptures (const char *s, Capture *capture, int n, int fd) { | 172 | static void adddyncaptures (Index_t index, Capture *capture, int n, int fd) { |
173 | int i; | 173 | int i; |
174 | assert(capture[-1].kind == Cgroup && capture[-1].siz == 0); | 174 | assert(capture[-1].kind == Cgroup && capture[-1].siz == 0); |
175 | capture[-1].idx = 0; /* make group capture an anonymous group */ | 175 | capture[-1].idx = 0; /* make group capture an anonymous group */ |
@@ -177,11 +177,11 @@ static void adddyncaptures (const char *s, Capture *capture, int n, int fd) { | |||
177 | capture[i].kind = Cruntime; | 177 | capture[i].kind = Cruntime; |
178 | capture[i].siz = 1; /* mark it as closed */ | 178 | capture[i].siz = 1; /* mark it as closed */ |
179 | capture[i].idx = fd + i; /* stack index of capture value */ | 179 | capture[i].idx = fd + i; /* stack index of capture value */ |
180 | capture[i].s = s; | 180 | capture[i].index = index; |
181 | } | 181 | } |
182 | capture[n].kind = Cclose; /* close group */ | 182 | capture[n].kind = Cclose; /* close group */ |
183 | capture[n].siz = 1; | 183 | capture[n].siz = 1; |
184 | capture[n].s = s; | 184 | capture[n].index = index; |
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
@@ -225,7 +225,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
225 | case IEnd: { | 225 | case IEnd: { |
226 | assert(stack == getstackbase(L, ptop) + 1); | 226 | assert(stack == getstackbase(L, ptop) + 1); |
227 | capture[captop].kind = Cclose; | 227 | capture[captop].kind = Cclose; |
228 | capture[captop].s = NULL; | 228 | capture[captop].index = MAXINDT; |
229 | return s; | 229 | return s; |
230 | } | 230 | } |
231 | case IGiveup: { | 231 | case IGiveup: { |
@@ -383,7 +383,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
383 | luaL_error(L, "too many results in match-time capture"); | 383 | luaL_error(L, "too many results in match-time capture"); |
384 | /* add new captures + close group to 'capture' list */ | 384 | /* add new captures + close group to 'capture' list */ |
385 | capture = growcap(L, capture, &capsize, captop, n + 1, ptop); | 385 | capture = growcap(L, capture, &capsize, captop, n + 1, ptop); |
386 | adddyncaptures(s, capture + captop, n, fr); | 386 | adddyncaptures(s - o, capture + captop, n, fr); |
387 | captop += n + 1; /* new captures + close group */ | 387 | captop += n + 1; /* new captures + close group */ |
388 | } | 388 | } |
389 | p++; | 389 | p++; |
@@ -394,24 +394,24 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
394 | assert(captop > 0); | 394 | assert(captop > 0); |
395 | /* if possible, turn capture into a full capture */ | 395 | /* if possible, turn capture into a full capture */ |
396 | if (capture[captop - 1].siz == 0 && | 396 | if (capture[captop - 1].siz == 0 && |
397 | s1 - capture[captop - 1].s < UCHAR_MAX) { | 397 | (s1 - o) - capture[captop - 1].index < UCHAR_MAX) { |
398 | capture[captop - 1].siz = s1 - capture[captop - 1].s + 1; | 398 | capture[captop - 1].siz = (s1 - o) - capture[captop - 1].index + 1; |
399 | p++; | 399 | p++; |
400 | continue; | 400 | continue; |
401 | } | 401 | } |
402 | else { | 402 | else { |
403 | capture[captop].siz = 1; /* mark entry as closed */ | 403 | capture[captop].siz = 1; /* mark entry as closed */ |
404 | capture[captop].s = s; | 404 | capture[captop].index = s - o; |
405 | goto pushcapture; | 405 | goto pushcapture; |
406 | } | 406 | } |
407 | } | 407 | } |
408 | case IOpenCapture: | 408 | case IOpenCapture: |
409 | capture[captop].siz = 0; /* mark entry as open */ | 409 | capture[captop].siz = 0; /* mark entry as open */ |
410 | capture[captop].s = s; | 410 | capture[captop].index = s - o; |
411 | goto pushcapture; | 411 | goto pushcapture; |
412 | case IFullCapture: | 412 | case IFullCapture: |
413 | capture[captop].siz = getoff(p) + 1; /* save capture size */ | 413 | capture[captop].siz = getoff(p) + 1; /* save capture size */ |
414 | capture[captop].s = s - getoff(p); | 414 | capture[captop].index = s - o - getoff(p); |
415 | /* goto pushcapture; */ | 415 | /* goto pushcapture; */ |
416 | pushcapture: { | 416 | pushcapture: { |
417 | capture[captop].idx = p->i.aux2.key; | 417 | capture[captop].idx = p->i.aux2.key; |