diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-07-01 10:51:26 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-07-01 19:32:22 (GMT) |
commit | 5726a6b4012cd41701927a6637b9f2070e7760ee (patch) | |
tree | a89b3b9c32f4399b80f1d2d15214b8d9799f4ec8 /run-command.c | |
parent | 3d97ea479fdcb88671105e2f2d04064bab110bd5 (diff) | |
download | git-5726a6b4012cd41701927a6637b9f2070e7760ee.zip git-5726a6b4012cd41701927a6637b9f2070e7760ee.tar.gz git-5726a6b4012cd41701927a6637b9f2070e7760ee.tar.bz2 |
*.c *_init(): define in terms of corresponding *_INIT macro
Change the common patter in the codebase of duplicating the
initialization logic between an *_INIT macro and a
corresponding *_init() function to use the macro as the canonical
source of truth.
Now we no longer need to keep the function up-to-date with the macro
version. This implements a suggestion by Jeff King who found that
under -O2 [1] modern compilers will init new version in place without
the extra copy[1]. The performance of a single *_init() won't matter
in most cases, but even if it does we're going to be producing
efficient machine code to perform these operations.
1. https://lore.kernel.org/git/YNyrDxUO1PlGJvCn@coredump.intra.peff.net/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'run-command.c')
-rw-r--r-- | run-command.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/run-command.c b/run-command.c index be6bc12..8750df1 100644 --- a/run-command.c +++ b/run-command.c @@ -11,9 +11,8 @@ void child_process_init(struct child_process *child) { - memset(child, 0, sizeof(*child)); - strvec_init(&child->args); - strvec_init(&child->env_array); + struct child_process blank = CHILD_PROCESS_INIT; + memcpy(child, &blank, sizeof(*child)); } void child_process_clear(struct child_process *child) |