mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Optimize xmemrchr()
This commit is contained in:
parent
436d2143fd
commit
f7399b05f9
14
nnn.c
14
nnn.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue