Skip to content

Commit dc8e943

Browse files
committed
lib/re1.5: Minor improvement in code size.
Signed-off-by: Andrew Leech <andrew@alelec.net>
1 parent de5848b commit dc8e943

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/re1.5/compilecode.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define INSERT_CODE(at, num, pc) \
1111
((code ? memmove(code + at + num, code + at, pc - at) : 0), pc += num)
1212
#define REL(at, to) (to - at - 2)
13-
#define EMIT(at, byte) (code ? (code[at] = byte) : (at))
13+
#define EMIT(at, byte) {int _at = at; code ? (code[_at] = byte) : (0);}
1414
#define EMIT_CHECKED(at, byte) (_emit_checked(at, code, byte, &err))
1515
#define PC (prog->bytelen)
1616

@@ -29,8 +29,9 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
2929
int term = PC;
3030
int alt_label = 0;
3131
const char *re_top = re + len;
32-
33-
while (re < re_top && *re != ')') {
32+
int remain;
33+
34+
while ((remain = re_top - re) && *re != ')') {
3435
switch (*re) {
3536
case '\\':
3637
re++;
@@ -80,8 +81,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
8081
goto emit_char_pair;
8182
}
8283
}
83-
if (!c) return NULL;
84-
if (re_top - re > 2 && re[1] == '-' && re[2] != ']') {
84+
if (remain > 2 && re[1] == '-' && re[2] != ']') {
8585
re += 2;
8686
}
8787
emit_char_pair:
@@ -94,7 +94,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
9494
case '(': {
9595
term = PC;
9696
int sub = 0;
97-
int capture = re_top - re > 2 && (re[1] != '?' || re[2] != ':');
97+
int capture = remain > 2 && (re[1] != '?' || re[2] != ':');
9898

9999
if (capture) {
100100
sub = ++prog->sub;
@@ -107,8 +107,8 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
107107

108108
re++;
109109
if (re >= re_top) return NULL; // Trailing bracket
110-
re = _compilecode(re, re_top - re, prog, sizecode);
111-
if (re == NULL || re >= re_top || *re != ')') return NULL; // error, or no matching paren
110+
re = _compilecode(re, remain, prog, sizecode);
111+
if (re == NULL || *re != ')') return NULL; // error, or no matching paren
112112

113113
if (capture) {
114114
EMIT(PC++, Save);
@@ -121,7 +121,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
121121
case '?':
122122
if (PC == term) return NULL; // nothing to repeat
123123
INSERT_CODE(term, 2, PC);
124-
if (re_top - re > 1 && re[1] == '?') {
124+
if (remain > 1 && re[1] == '?') {
125125
EMIT(term, RSplit);
126126
re++;
127127
} else {
@@ -137,7 +137,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
137137
EMIT(PC, Jmp);
138138
EMIT_CHECKED(PC + 1, REL(PC, term));
139139
PC += 2;
140-
if (re_top - re > 1 && re[1] == '?') {
140+
if (remain > 1 && re[1] == '?') {
141141
EMIT(term, RSplit);
142142
re++;
143143
} else {
@@ -149,7 +149,7 @@ static const char *_compilecode(const char *re, size_t len, ByteProg *prog, int
149149
break;
150150
case '+':
151151
if (PC == term) return NULL; // nothing to repeat
152-
if (re_top - re > 1 && re[1] == '?') {
152+
if (remain > 1 && re[1] == '?') {
153153
EMIT(PC, Split);
154154
re++;
155155
} else {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy