mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51: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 *
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue