chars: speed up two reverse-searching routines a bit

By removing from their main loops a condition that occurs just once.
master
Benno Schulenberg 2016-06-25 21:04:19 +02:00
parent 1e2833e07b
commit 6fda7a7057
1 changed files with 14 additions and 8 deletions

View File

@ -813,11 +813,14 @@ char *revstrpbrk(const char *s, const char *accept, const char
{
assert(s != NULL && accept != NULL && rev_start != NULL);
for (; rev_start >= s; rev_start--) {
const char *q = (*rev_start == '\0') ? NULL : strchr(accept,
*rev_start);
if (*rev_start == '\0') {
if (rev_start == s)
return NULL;
rev_start--;
}
if (q != NULL)
for (; rev_start >= s; rev_start--) {
if (strchr(accept, *rev_start) != NULL)
return (char *)rev_start;
}
@ -833,11 +836,14 @@ char *mbrevstrpbrk(const char *s, const char *accept, const char
#ifdef ENABLE_UTF8
if (use_utf8) {
while (TRUE) {
const char *q = (*rev_start == '\0') ?
NULL : mbstrchr(accept, rev_start);
if (*rev_start == '\0') {
if (rev_start == s)
return NULL;
rev_start = s + move_mbleft(s, rev_start - s);
}
if (q != NULL)
while (TRUE) {
if (mbstrchr(accept, rev_start) != NULL)
return (char *)rev_start;
/* If we've reached the head of the string, we found nothing. */