Optimize xmemrchr()

This commit is contained in:
Arun Prakash Jana 2017-12-25 01:44:48 +05:30
parent 436d2143fd
commit f7399b05f9
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 8 additions and 6 deletions

14
nnn.c
View File

@ -433,17 +433,19 @@ xstrcmp(const char *s1, const char *s2)
static void *
xmemrchr(uchar *s, uchar ch, size_t n)
{
static uchar *ptr;
if (!s || !n)
return NULL;
s = s + n - 1;
ptr = s + n;
while (n) {
if (*s == ch)
return s;
do {
--ptr;
--n, --s;
}
if (*ptr == ch)
return ptr;
} while (s != ptr);
return NULL;
}