diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-09 12:44:55 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-01-09 12:44:55 -0200 |
commit | 0e1058cfdd07a3751fce1c79b75241cf770266cf (patch) | |
tree | f8ef57ce0f480bfd3653808f17b6b10b45394633 /lstrlib.c | |
parent | 26679b1a48de4f7cfcde985764cb31c78ece4fc3 (diff) | |
download | lua-0e1058cfdd07a3751fce1c79b75241cf770266cf.tar.gz lua-0e1058cfdd07a3751fce1c79b75241cf770266cf.tar.bz2 lua-0e1058cfdd07a3751fce1c79b75241cf770266cf.zip |
small optimizations in switch order
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.4 1997/12/15 17:58:49 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.5 1997/12/17 20:48:58 roberto Exp roberto $ |
3 | ** Standard library for strings and pattern-matching | 3 | ** Standard library for strings and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -165,14 +165,14 @@ static int matchclass (int c, int cl) | |||
165 | int res; | 165 | int res; |
166 | if (c == 0) return 0; | 166 | if (c == 0) return 0; |
167 | switch (tolower((unsigned char)cl)) { | 167 | switch (tolower((unsigned char)cl)) { |
168 | case 'a' : res = isalpha((unsigned char)c); break; | 168 | case 'w' : res = isalnum((unsigned char)c); break; |
169 | case 'c' : res = iscntrl((unsigned char)c); break; | ||
170 | case 'd' : res = isdigit((unsigned char)c); break; | 169 | case 'd' : res = isdigit((unsigned char)c); break; |
171 | case 'l' : res = islower((unsigned char)c); break; | ||
172 | case 'p' : res = ispunct((unsigned char)c); break; | ||
173 | case 's' : res = isspace((unsigned char)c); break; | 170 | case 's' : res = isspace((unsigned char)c); break; |
171 | case 'a' : res = isalpha((unsigned char)c); break; | ||
172 | case 'p' : res = ispunct((unsigned char)c); break; | ||
173 | case 'l' : res = islower((unsigned char)c); break; | ||
174 | case 'u' : res = isupper((unsigned char)c); break; | 174 | case 'u' : res = isupper((unsigned char)c); break; |
175 | case 'w' : res = isalnum((unsigned char)c); break; | 175 | case 'c' : res = iscntrl((unsigned char)c); break; |
176 | default: return (cl == c); | 176 | default: return (cl == c); |
177 | } | 177 | } |
178 | return (islower((unsigned char)cl) ? res : !res); | 178 | return (islower((unsigned char)cl) ? res : !res); |
@@ -182,12 +182,12 @@ static int matchclass (int c, int cl) | |||
182 | int luaI_singlematch (int c, char *p, char **ep) | 182 | int luaI_singlematch (int c, char *p, char **ep) |
183 | { | 183 | { |
184 | switch (*p) { | 184 | switch (*p) { |
185 | case '\0': | ||
186 | *ep = p; | ||
187 | return 0; | ||
188 | case '.': | 185 | case '.': |
189 | *ep = p+1; | 186 | *ep = p+1; |
190 | return (c != 0); | 187 | return (c != 0); |
188 | case '\0': | ||
189 | *ep = p; | ||
190 | return 0; | ||
191 | case ESC: | 191 | case ESC: |
192 | if (*(++p) == '\0') | 192 | if (*(++p) == '\0') |
193 | luaL_verror("incorrect pattern (ends with `%c')", ESC); | 193 | luaL_verror("incorrect pattern (ends with `%c')", ESC); |
@@ -294,6 +294,12 @@ static char *match (char *s, char *p, struct Capture *cap) | |||
294 | return res; | 294 | return res; |
295 | p=ep+1; goto init; /* else return match(s, ep+1, cap); */ | 295 | p=ep+1; goto init; /* else return match(s, ep+1, cap); */ |
296 | } | 296 | } |
297 | case '?': { /* optional */ | ||
298 | char *res; | ||
299 | if (s1 && (res = match(s1, ep+1, cap))) | ||
300 | return res; | ||
301 | p=ep+1; goto init; /* else return match(s, ep+1, cap); */ | ||
302 | } | ||
297 | case '-': { /* repetition */ | 303 | case '-': { /* repetition */ |
298 | char *res; | 304 | char *res; |
299 | if ((res = match(s, ep+1, cap)) != 0) | 305 | if ((res = match(s, ep+1, cap)) != 0) |
@@ -305,12 +311,6 @@ static char *match (char *s, char *p, struct Capture *cap) | |||
305 | else | 311 | else |
306 | return NULL; | 312 | return NULL; |
307 | } | 313 | } |
308 | case '?': { /* optional */ | ||
309 | char *res; | ||
310 | if (s1 && (res = match(s1, ep+1, cap))) | ||
311 | return res; | ||
312 | p=ep+1; goto init; /* else return match(s, ep+1, cap); */ | ||
313 | } | ||
314 | default: | 314 | default: |
315 | if (s1) { s=s1; p=ep; goto init; } /* return match(s1, ep, cap); */ | 315 | if (s1) { s=s1; p=ep; goto init; } /* return match(s1, ep, cap); */ |
316 | else return NULL; | 316 | else return NULL; |