git-commit-vandalism/builtin
Taylor Blau 52acddf36c string-list: multi-delimiter string_list_split_in_place()
Enhance `string_list_split_in_place()` to accept multiple characters as
delimiters instead of a single character.

Instead of using `strchr(2)` to locate the first occurrence of the given
delimiter character, `string_list_split_in_place_multi()` uses
`strcspn(2)` to move past the initial segment of characters comprised of
any characters in the delimiting set.

When only a single delimiting character is provided, `strpbrk(2)` (which
is implemented with `strcspn(2)`) has equivalent performance to
`strchr(2)`. Modern `strcspn(2)` implementations treat an empty
delimiter or the singleton delimiter as a special case and fall back to
calling strchrnul(). Both glibc[1] and musl[2] implement `strcspn(2)`
this way.

This change is one step to removing `strtok(2)` from the tree. Note that
`string_list_split_in_place()` is not a strict replacement for
`strtok()`, since it will happily turn sequential delimiter characters
into empty entries in the resulting string_list. For example:

    string_list_split_in_place(&xs, "foo:;:bar:;:baz", ":;", -1)

would yield a string list of:

    ["foo", "", "", "bar", "", "", "baz"]

Callers that wish to emulate the behavior of strtok(2) more directly
should call `string_list_remove_empty_items()` after splitting.

To avoid regressions for the new multi-character delimter cases, update
t0063 in this patch as well.

[1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strcspn.c;hb=glibc-2.37#l35
[2]: https://git.musl-libc.org/cgit/musl/tree/src/string/strcspn.c?h=v1.2.3#n11

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-04-24 16:01:28 -07:00
..
add.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
am.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
annotate.c
apply.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
archive.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
bisect.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
blame.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
branch.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
bugreport.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
bundle.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
cat-file.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
check-attr.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
check-ignore.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
check-mailmap.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
check-ref-format.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
checkout--worker.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
checkout-index.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
checkout.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
clean.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
clone.c Merge branch 'jc/clone-object-format-from-void' 2023-04-11 13:49:13 -07:00
column.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
commit-graph.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
commit-tree.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
commit.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
config.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
count-objects.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
credential-cache--daemon.c abspath.h: move absolute path functions from cache.h 2023-03-21 10:56:52 -07:00
credential-cache.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
credential-store.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
credential.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
describe.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
diagnose.c abspath.h: move absolute path functions from cache.h 2023-03-21 10:56:52 -07:00
diff-files.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
diff-index.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
diff-tree.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
diff.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
difftool.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fast-export.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fast-import.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fetch-pack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fetch.c Merge branch 'ds/fetch-bundle-uri-with-all' 2023-04-06 13:38:32 -07:00
fmt-merge-msg.c wrapper.h: move declarations for wrapper.c functions from cache.h 2023-03-21 10:56:53 -07:00
for-each-ref.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
for-each-repo.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fsck.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
fsmonitor--daemon.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
gc.c string-list: multi-delimiter string_list_split_in_place() 2023-04-24 16:01:28 -07:00
get-tar-commit-id.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
grep.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
hash-object.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
help.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
hook.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
index-pack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
init-db.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
interpret-trailers.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
log.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
ls-files.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
ls-remote.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
ls-tree.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
mailinfo.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
mailsplit.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge-base.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge-file.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
merge-index.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
merge-ours.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
merge-recursive.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge-tree.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
merge.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
mktag.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
mktree.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
multi-pack-index.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
mv.c setup.h: move declarations for setup.c functions from cache.h 2023-03-21 10:56:54 -07:00
name-rev.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
notes.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pack-objects.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pack-redundant.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pack-refs.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
patch-id.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
prune-packed.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
prune.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
pull.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
push.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00
range-diff.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
read-tree.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
rebase.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
receive-pack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
reflog.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
remote-ext.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote-fd.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
remote.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
repack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
replace.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
rerere.c wrapper.h: move declarations for wrapper.c functions from cache.h 2023-03-21 10:56:53 -07:00
reset.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
rev-list.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
rev-parse.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
revert.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
rm.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
send-pack.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
shortlog.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
show-branch.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
show-index.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
show-ref.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
sparse-checkout.c Merge branch 'ws/sparse-check-rules' 2023-04-11 13:49:12 -07:00
stash.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
stripspace.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
submodule--helper.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
symbolic-ref.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
tag.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
unpack-file.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
unpack-objects.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
update-index.c write-or-die.h: move declarations for write-or-die.c functions from cache.h 2023-03-21 10:56:54 -07:00
update-ref.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
update-server-info.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
upload-archive.c builtins: annotate always-empty prefix parameters 2023-03-28 14:11:24 -07:00
upload-pack.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
var.c builtins: mark unused prefix parameters 2023-03-28 14:11:24 -07:00
verify-commit.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
verify-pack.c treewide: be explicit about dependence on gettext.h 2023-03-21 10:56:51 -07:00
verify-tag.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
worktree.c Merge branch 'en/header-split-cleanup' 2023-04-06 13:38:31 -07:00
write-tree.c environment.h: move declarations for environment.c functions from cache.h 2023-03-21 10:56:53 -07:00