diff options
| author | 2017-12-25 01:44:48 +0530 | |
|---|---|---|
| committer | 2017-12-25 01:44:48 +0530 | |
| commit | f7399b05f94c3bf39469d7255b619850534da58f (patch) | |
| tree | f6976b31b2ca5b8f725cccb3c534bbd1e90844da | |
| parent | 436d2143fd6d4d5b39c1e0e01762b15d4558a6e2 (diff) | |
| download | nnn-f7399b05f94c3bf39469d7255b619850534da58f.tar.gz | |
Optimize xmemrchr()
| -rw-r--r-- | nnn.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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; } |