diff options
author | Vladimir Gavrilov <105977161+0xA50C1A1@users.noreply.github.com> | 2025-05-12 10:46:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-12 09:46:54 +0200 |
commit | 43248244b8753f9ee2162e7e8ce3f407c2149d6f (patch) | |
tree | 3c5ee5f0be1555dd5238c51dcf262a2666c5cbf7 /src/lib/ndpi_main.c | |
parent | 292d26f0dbb3eede04647b63fccd10216abb47bb (diff) |
Micro-optimizations of 'ndpi_strncasestr' and 'LINE_*' macros (#2808)
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r-- | src/lib/ndpi_main.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 0146f5b18..0cc57e19b 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -10533,10 +10533,18 @@ const char * ndpi_strncasestr(const char *s, const char *find, size_t len) { const size_t s_len = strnlen(s, len); + /* If 'find' is longer than 's', no match is possible */ + if (find_len > s_len) { + return NULL; + } + const char *const end_of_search = s + s_len - find_len + 1; + /* Cache the lowercased first character of 'find' */ + const unsigned char fc = tolower((unsigned char) *find); + for (; s < end_of_search; ++s) { - if (tolower((unsigned char)*s) == tolower((unsigned char)*find)) { + if (tolower((unsigned char)*s) == fc) { if (strncasecmp(s + 1, find + 1, find_len - 1) == 0) { return s; } |