in nstrcasestr(), mbstrcasestr(), revstrstr(), revstrcasestr(), and

mbrevstrcasestr(), for efficiency, return haystack immediately if needle
is blank


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4122 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2007-07-02 15:45:13 +00:00
parent 444f802d58
commit 710583064f
2 changed files with 21 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2007-07-02 David Lawrence Ramsey <pooka109@gmail.com>
* chars.c (nstrcasestr, mbstrcasestr, revstrstr, revstrcasestr,
mbrevstrcasestr): For efficiency, return haystack immediately if
needle is blank.
2007-07-01 David Lawrence Ramsey <pooka109@gmail.com>
* chars.c (nstrncasecmp, mbstrncasecmp): For efficiency, return

View File

@ -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);