nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 6967fae35d2b712a6fe6dc863f9fe89f7d84c4d0
parent a37435141ae2ad88dc9e07b7946c3c4410b63080
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Fri, 28 Apr 2017 21:55:32 +0200

tweaks: use the logic from revstrstr() also in revstrcasestr()

This elides a counter and a comparison from the central loop,
and thus makes the search a tiny bit faster.

Diffstat:
Msrc/chars.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/chars.c b/src/chars.c @@ -507,22 +507,22 @@ char *revstrstr(const char *haystack, const char *needle, char *revstrcasestr(const char *haystack, const char *needle, const char *index) { - size_t tail_len, needle_len; + size_t needle_len = strlen(needle); + size_t tail_len = strlen(index); - if (*needle == '\0') + if (needle_len == 0) return (char *)index; - needle_len = strlen(needle); - if (strlen(haystack) < needle_len) return NULL; - tail_len = strlen(index); + if (tail_len < needle_len) + index += tail_len - needle_len; - for (; index >= haystack; index--, tail_len++) { - if (tail_len >= needle_len && - strncasecmp(index, needle, needle_len) == 0) + while (index >= haystack) { + if (strncasecmp(index, needle, needle_len) == 0) return (char *)index; + index--; } return NULL;