Browse Source

Optimize xmemrchr()

master
Arun Prakash Jana 7 years ago
parent
commit
f7399b05f9
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 changed files with 8 additions and 6 deletions
  1. +8
    -6
      nnn.c

+ 8
- 6
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) {
if (*s == ch)
return s;
do {
--ptr;


--n, --s;
}
if (*ptr == ch)
return ptr;
} while (s != ptr);


return NULL; return NULL;
} }


Loading…
Cancel
Save