[PATCH 2/2] string: vectorize strspn single-accept-char case

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Aug 13 22:34:53 GMT 2026


Hi Matt,

+      do
+	{
+	  word = *++word_ptr;
+	  mask = find_ne_all (word, repeated_c);
+	}
+      while (mask == 0);
+
+      return (const char *) word_ptr - str + index_first (mask);

And this should obviously be:

do
  {
    word = *++word_ptr;
  }
while (word == repeated_c);

return (const char *) word_ptr - str + index_first (find_ne_all (word, repeated_c));

That makes the loop several times faster.

Whether it is worth optimizing this at all is another question - are people actually
using single-char strspn for performance critical things? Scanners certainly don't,
so the most likely scenario might be skipping repeated slashes in path names...

Cheers,
Wilco


More information about the Libc-alpha mailing list