string-util: add minor optimization to strrstr()
This commit is contained in:
@@ -1519,13 +1519,17 @@ char* strrstr_internal(const char *haystack, const char *needle) {
|
||||
|
||||
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
|
||||
* last char, not before. */
|
||||
if (*needle == 0)
|
||||
if (needle[0] == 0)
|
||||
return (char*) strchr(haystack, 0);
|
||||
|
||||
/* Special case: for single character strings, just use optimized strrchr() */
|
||||
if (needle[1] == 0)
|
||||
return (char*) strrchr(haystack, needle[0]);
|
||||
|
||||
for (const char *p = strstr(haystack, needle), *q; p; p = q) {
|
||||
q = strstr(p + 1, needle);
|
||||
if (!q)
|
||||
return (char *) p;
|
||||
return (char*) p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user