+2023-08-26 Paul Eggert <eggert@cs.ucla.edu>
+
+ propername: tune single-byte code
+ * lib/propername.c (mbsstr_trimmed_wordbounded): Cache MB_CUR_MAX.
+ Simplify word boundary detection in single-byte code.
+
2023-08-26 Paul Eggert <eggert@cs.ucla.edu>
Tune single-byte code involving tolower
{
char *tsub = trim (sub);
bool found = false;
+ bool multibyte_locale = MB_CUR_MAX > 1;
+ size_t tsublen;
+ if (! multibyte_locale)
+ tsublen = strlen (tsub);
- for (; *string != '\0';)
+ while (*string != '\0')
{
const char *tsub_in_string = mbsstr (string, tsub);
if (tsub_in_string == NULL)
break;
else
{
- if (MB_CUR_MAX > 1)
+ if (multibyte_locale)
{
mbui_iterator_t string_iter;
bool word_boundary_before;
}
else
{
- bool word_boundary_before;
- const char *p;
- bool word_boundary_after;
-
- word_boundary_before = true;
- if (string < tsub_in_string)
- if (isalnum ((unsigned char) tsub_in_string[-1]))
- word_boundary_before = false;
-
- p = tsub_in_string + strlen (tsub);
- word_boundary_after = true;
- if (*p != '\0')
- if (isalnum ((unsigned char) *p))
- word_boundary_after = false;
-
- if (word_boundary_before && word_boundary_after)
+ if ((string == tsub_in_string
+ || !isalnum ((unsigned char) tsub_in_string[-1]))
+ && !isalnum ((unsigned char) tsub_in_string[tsublen]))
{
found = true;
break;