From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
Phillip Wood <phillip.wood123@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v2 2/7] strvec: declare the `strvec_push_nodup()` function globally
Date: Thu, 11 Jul 2024 23:11:31 +0000 [thread overview]
Message-ID: <91ebccbc39f21fa73af8bc8c81af721f1ca201bd.1720739496.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1760.v2.git.1720739496.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
This function differs from `strvec_push()` in that it takes ownership of
the allocated string that is passed as second argument.
This is useful when appending elements to the string array that have
been freshly allocated and serve no further other purpose after that.
Without declaring this function globally, call sites would allocate the
memory, only to have `strvec_push()` duplicate the string, and then the
first copy would need to be released. Having this function globally
avoids that kind of unnecessary work.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
strvec.c | 2 +-
strvec.h | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/strvec.c b/strvec.c
index d4073ec9fa2..f712070f574 100644
--- a/strvec.c
+++ b/strvec.c
@@ -10,7 +10,7 @@ void strvec_init(struct strvec *array)
memcpy(array, &blank, sizeof(*array));
}
-static void strvec_push_nodup(struct strvec *array, const char *value)
+void strvec_push_nodup(struct strvec *array, char *value)
{
if (array->v == empty_strvec)
array->v = NULL;
diff --git a/strvec.h b/strvec.h
index 6c7e8b7d503..4b73c1f092e 100644
--- a/strvec.h
+++ b/strvec.h
@@ -46,6 +46,9 @@ void strvec_init(struct strvec *);
/* Push a copy of a string onto the end of the array. */
const char *strvec_push(struct strvec *, const char *);
+/* Push an allocated string onto the end of the array, taking ownership. */
+void strvec_push_nodup(struct strvec *array, char *value);
+
/**
* Format a string and push it onto the end of the array. This is a
* convenience wrapper combining `strbuf_addf` and `strvec_push`.
--
gitgitgadget
next prev parent reply other threads:[~2024-07-11 23:11 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 13:02 [PATCH] var(win32): do report the GIT_SHELL_PATH that is actually used Johannes Schindelin via GitGitGadget
2024-07-08 18:54 ` Junio C Hamano
2024-07-08 23:40 ` brian m. carlson
2024-07-08 23:55 ` Junio C Hamano
2024-07-09 0:25 ` brian m. carlson
2024-07-09 16:31 ` Junio C Hamano
2024-07-09 13:53 ` Phillip Wood
2024-07-08 19:03 ` Junio C Hamano
2024-07-09 8:55 ` Phillip Wood
2024-07-11 12:03 ` Johannes Schindelin
2024-07-17 14:55 ` phillip.wood123
2024-07-11 23:11 ` [PATCH v2 0/7] " Johannes Schindelin via GitGitGadget
2024-07-11 23:11 ` [PATCH v2 1/7] run-command: refactor getting the Unix shell path into its own function Johannes Schindelin via GitGitGadget
2024-07-11 23:11 ` Johannes Schindelin via GitGitGadget [this message]
2024-07-11 23:11 ` [PATCH v2 3/7] win32: override `fspathcmp()` with a directory separator-aware version Johannes Schindelin via GitGitGadget
2024-07-12 13:46 ` Phillip Wood
2024-07-11 23:11 ` [PATCH v2 4/7] mingw(is_msys2_sh): handle forward slashes in the `sh.exe` path, too Johannes Schindelin via GitGitGadget
2024-07-12 13:49 ` Phillip Wood
2024-07-11 23:11 ` [PATCH v2 5/7] run-command(win32): resolve the path to the Unix shell early Johannes Schindelin via GitGitGadget
2024-07-11 23:11 ` [PATCH v2 6/7] run-command: declare the `git_shell_path()` function globally Johannes Schindelin via GitGitGadget
2024-07-11 23:11 ` [PATCH v2 7/7] var(win32): do report the GIT_SHELL_PATH that is actually used Johannes Schindelin via GitGitGadget
2024-07-12 15:35 ` Junio C Hamano
2024-07-12 13:51 ` [PATCH v2 0/7] " Phillip Wood
2024-07-12 22:16 ` Junio C Hamano
2024-07-13 21:08 ` [PATCH v3 " Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 1/7] run-command: refactor getting the Unix shell path into its own function Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 2/7] strvec: declare the `strvec_push_nodup()` function globally Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 3/7] win32: override `fspathcmp()` with a directory separator-aware version Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 4/7] mingw(is_msys2_sh): handle forward slashes in the `sh.exe` path, too Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 5/7] run-command(win32): resolve the path to the Unix shell early Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 6/7] run-command: declare the `git_shell_path()` function globally Johannes Schindelin via GitGitGadget
2024-07-13 21:08 ` [PATCH v3 7/7] var(win32): do report the GIT_SHELL_PATH that is actually used Johannes Schindelin via GitGitGadget
2024-07-17 14:51 ` [PATCH v3 0/7] " Phillip Wood
2024-07-17 22:47 ` brian m. carlson
2024-07-17 22:51 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=91ebccbc39f21fa73af8bc8c81af721f1ca201bd.1720739496.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=phillip.wood123@gmail.com \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).