char *start = *stringp;
char *ptr;
- if (!start)
+ if (start == NULL)
return NULL;
- if (!*delim)
- ptr = start + strlen (start);
+ /* Optimize the case of no delimiters. */
+ if (delim[0] == '\0')
+ {
+ *stringp = NULL;
+ return start;
+ }
+
+ /* Optimize the case of one delimiter. */
+ if (delim[1] == '\0')
+ ptr = strchr (start, delim[0]);
else
+ /* The general case. */
+ ptr = strpbrk (start, delim);
+ if (ptr == NULL)
{
- ptr = strpbrk (start, delim);
- if (!ptr)
- {
- *stringp = NULL;
- return start;
- }
+ *stringp = NULL;
+ return start;
}
*ptr = '\0';