aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-16 09:56:04 +0000
committerRon Yorston <rmy@pobox.com>2020-02-16 09:56:04 +0000
commit5f6aaf23076dd0f523eccf821987276cc36080ae (patch)
treee00173009b91dce88720ceb705ea116dc20f00ea
parent8d443464257edcd04c8fa8d5a6f130b70535e115 (diff)
downloadbusybox-w32-5f6aaf23076dd0f523eccf821987276cc36080ae.tar.gz
busybox-w32-5f6aaf23076dd0f523eccf821987276cc36080ae.tar.bz2
busybox-w32-5f6aaf23076dd0f523eccf821987276cc36080ae.zip
win32: save bytes in fnmatch
Replace several explicit string comparisons with a single call to index_in_strings(). Saves 304 bytes.
-rw-r--r--win32/fnmatch.c68
1 files changed, 55 insertions, 13 deletions
diff --git a/win32/fnmatch.c b/win32/fnmatch.c
index de456e526..5d2ea685d 100644
--- a/win32/fnmatch.c
+++ b/win32/fnmatch.c
@@ -17,6 +17,7 @@
17 Boston, MA 02111-1307, USA. */ 17 Boston, MA 02111-1307, USA. */
18 18
19#include <platform.h> 19#include <platform.h>
20int index_in_strings(const char *strings, const char *key) FAST_FUNC;
20 21
21#if HAVE_CONFIG_H 22#if HAVE_CONFIG_H
22# include <config.h> 23# include <config.h>
@@ -372,19 +373,60 @@ internal_fnmatch (const char *pattern, const char *string,
372 if (__iswctype (__btowc ((unsigned char) *n), wt)) 373 if (__iswctype (__btowc ((unsigned char) *n), wt))
373 goto matched; 374 goto matched;
374# else 375# else
375 if ((STREQ (str, "alnum") && ISALNUM ((unsigned char) *n)) 376#define CHAR_CLASSES \
376 || (STREQ (str, "alpha") && ISALPHA ((unsigned char) *n)) 377 "alnum\0alpha\0blank\0cntrl\0digit\0graph\0" \
377 || (STREQ (str, "blank") && ISBLANK ((unsigned char) *n)) 378 "lower\0print\0punct\0space\0upper\0xdigit\0"
378 || (STREQ (str, "cntrl") && ISCNTRL ((unsigned char) *n)) 379
379 || (STREQ (str, "digit") && ISDIGIT ((unsigned char) *n)) 380 switch (index_in_strings(CHAR_CLASSES, str)) {
380 || (STREQ (str, "graph") && ISGRAPH ((unsigned char) *n)) 381 case 0:
381 || (STREQ (str, "lower") && ISLOWER ((unsigned char) *n)) 382 if (ISALNUM ((unsigned char) *n))
382 || (STREQ (str, "print") && ISPRINT ((unsigned char) *n)) 383 goto matched;
383 || (STREQ (str, "punct") && ISPUNCT ((unsigned char) *n)) 384 break;
384 || (STREQ (str, "space") && ISSPACE ((unsigned char) *n)) 385 case 1:
385 || (STREQ (str, "upper") && ISUPPER ((unsigned char) *n)) 386 if (ISALPHA ((unsigned char) *n))
386 || (STREQ (str, "xdigit") && ISXDIGIT ((unsigned char) *n))) 387 goto matched;
387 goto matched; 388 break;
389 case 2:
390 if (ISBLANK ((unsigned char) *n))
391 goto matched;
392 break;
393 case 3:
394 if (ISCNTRL ((unsigned char) *n))
395 goto matched;
396 break;
397 case 4:
398 if (ISDIGIT ((unsigned char) *n))
399 goto matched;
400 break;
401 case 5:
402 if (ISGRAPH ((unsigned char) *n))
403 goto matched;
404 break;
405 case 6:
406 if (ISLOWER ((unsigned char) *n))
407 goto matched;
408 break;
409 case 7:
410 if (ISPRINT ((unsigned char) *n))
411 goto matched;
412 break;
413 case 8:
414 if (ISPUNCT ((unsigned char) *n))
415 goto matched;
416 break;
417 case 9:
418 if (ISSPACE ((unsigned char) *n))
419 goto matched;
420 break;
421 case 10:
422 if (ISUPPER ((unsigned char) *n))
423 goto matched;
424 break;
425 case 11:
426 if (ISXDIGIT ((unsigned char) *n))
427 goto matched;
428 break;
429 }
388# endif 430# endif
389 } 431 }
390 else if (c == '\0') 432 else if (c == '\0')