Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-07-01 13:51:26 +0300
committerJunio C Hamano <gitster@pobox.com>2021-07-01 22:32:22 +0300
commit5726a6b4012cd41701927a6637b9f2070e7760ee (patch)
treea89b3b9c32f4399b80f1d2d15214b8d9799f4ec8 /strbuf.c
parent3d97ea479fdcb88671105e2f2d04064bab110bd5 (diff)
*.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 'strbuf.c')
-rw-r--r--strbuf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/strbuf.c b/strbuf.c
index 4df30b4549..c8a5789694 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -52,8 +52,8 @@ char strbuf_slopbuf[1];
void strbuf_init(struct strbuf *sb, size_t hint)
{
- sb->alloc = sb->len = 0;
- sb->buf = strbuf_slopbuf;
+ struct strbuf blank = STRBUF_INIT;
+ memcpy(sb, &blank, sizeof(*sb));
if (hint)
strbuf_grow(sb, hint);
}