From: David Lawrence Ramsey Date: Mon, 2 Jul 2007 15:51:26 +0000 (+0000) Subject: in nstrcasestr(), mbstrcasestr(), revstrstr(), revstrcasestr(), and X-Git-Tag: v2.0.7~79 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=0c4736c7c0ffdc79f0ae1b977cc0e8c2afe17f04;p=nano.git in nstrcasestr(), mbstrcasestr(), revstrstr(), revstrcasestr(), and mbrevstrcasestr(), for efficiency, return haystack immediately if needle/rev_start is blank git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4124 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index d45fcb0c..8441d8d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,10 @@ CVS code - nstrncasecmp(), mbstrncasecmp() - For efficiency, return zero immediately if s1 and s2 point to the same string. (DLR) + nstrcasestr(), mbstrcasestr(), revstrstr(), revstrcasestr(), + mbrevstrcasestr() + - For efficiency, return haystack immediately if + needle/rev_start is blank. (DLR) - prompt.c: do_yesno_prompt() - Remove redundant check for NO_HELP's being FALSE. (DLR) diff --git a/src/chars.c b/src/chars.c index 9a79065a..888c035f 100644 --- a/src/chars.c +++ b/src/chars.c @@ -606,6 +606,9 @@ const char *nstrcasestr(const char *haystack, const char *needle) { assert(haystack != NULL && needle != NULL); + if (needle == '\0') + return haystack; + for (; *haystack != '\0'; haystack++) { const char *r = haystack, *q = needle; @@ -631,6 +634,9 @@ const char *mbstrcasestr(const char *haystack, const char *needle) assert(haystack != NULL && needle != NULL); + if (needle == '\0') + return haystack; + r_mb = charalloc(MB_CUR_MAX); q_mb = charalloc(MB_CUR_MAX); @@ -690,6 +696,9 @@ const char *revstrstr(const char *haystack, const char *needle, const { assert(haystack != NULL && needle != NULL && rev_start != NULL); + if (needle == '\0') + return rev_start; + for (; rev_start >= haystack; rev_start--) { const char *r, *q; @@ -712,6 +721,9 @@ const char *revstrcasestr(const char *haystack, const char *needle, { assert(haystack != NULL && needle != NULL && rev_start != NULL); + if (needle == '\0') + return rev_start; + for (; rev_start >= haystack; rev_start--) { const char *r = rev_start, *q = needle; @@ -739,6 +751,9 @@ const char *mbrevstrcasestr(const char *haystack, const char *needle, assert(haystack != NULL && needle != NULL && rev_start != NULL); + if (needle == '\0') + return rev_start; + r_mb = charalloc(MB_CUR_MAX); q_mb = charalloc(MB_CUR_MAX);