diff options
author | 2014-04-07 09:45:41 +0000 | |
---|---|---|
committer | 2014-04-07 09:45:41 +0000 | |
commit | 0e35e130fd395e7d6d7e1ba5dc003805357b9df9 (patch) | |
tree | 6a925757420cc7f765ccaeca0d32be0c5f07da59 | |
parent | eeb9af72eee2dae6ec48607852d6b3927819cd4d (diff) |
small core_strwildcmp() optimization when empty strings are involved (nw)
-rw-r--r-- | src/lib/util/corestr.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/util/corestr.c b/src/lib/util/corestr.c index c0d71da855c..a8e49f9b1f6 100644 --- a/src/lib/util/corestr.c +++ b/src/lib/util/corestr.c @@ -58,12 +58,17 @@ int core_strnicmp(const char *s1, const char *s2, size_t n) int core_strwildcmp(const char *sp1, const char *sp2) { char s1[17], s2[17]; - int i, l1, l2; + size_t i, l1, l2; char *p; - strncpy(s1, sp1, 16); s1[16] = 0; if (s1[0] == 0) strcpy(s1, "*"); + //assert(strlen(sp1) < 16); + //assert(strlen(sp2) < 16); - strncpy(s2, sp2, 16); s2[16] = 0; if (s2[0] == 0) strcpy(s2, "*"); + if (sp1[0] == 0) strcpy(s1, "*"); + else { strncpy(s1, sp1, 16); s1[16] = 0; } + + if (sp2[0] == 0) strcpy(s2, "*"); + else { strncpy(s2, sp2, 16); s2[16] = 0; } p = strchr(s1, '*'); if (p) @@ -79,14 +84,14 @@ int core_strwildcmp(const char *sp1, const char *sp2) s2[16] = 0; } - l1 = (int)strlen(s1); + l1 = strlen(s1); if (l1 < 16) { for (i = l1 + 1; i < 16; i++) s1[i] = ' '; s1[16] = 0; } - l2 = (int)strlen(s2); + l2 = strlen(s2); if (l2 < 16) { for (i = l2 + 1; i < 16; i++) s2[i] = ' '; |