Re: [PATCH 1/5] string-list: introduce `string_list_split_in_place_multi()`
- From
Jeff King <peff@peff.net>
- Date
- Apr 18, 2023, 10:10 UTC
- Message-ID
- <20230418101058.GA508219@coredump.intra.peff.net>
- In-Reply-To
- <dda218c8c1fdc0ca2e4352b820f3432565a74a23.1681428696.git.me@ttaylorr.com>
On Thu, Apr 13, 2023 at 07:31:43PM -0400, Taylor Blau wrote:
Show 9 quoted lines
> Instead of using `strchr(2)` to locate the first occurrence of the given > delimiter character, `string_list_split_in_place_multi()` uses > `strpbrk(2)` to find the first occurrence of *any* character in the given > delimiter string. > > Since the `_multi` variant is a generalization of the original > implementation, reimplement `string_list_split_in_place()` in terms of > the more general function by providing a single-character string for the > list of accepted delimiters.
I'd imagine that strpbrk() is potentially a lot slower than strchr(). But I kind of doubt that splitting is such a hot path that it will matter. If we want to care, I think we could do something like:
end = delim[1] ? strpbrk(p, delim) : strchr(p, delim[0]);
It's entirely possible that a half-decent strpbrk() implementation does this already.
So I mention it mostly in case we need to revisit this later. I think it's OK to ignore for now.
-Peff