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

14
nnn.c
View file

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