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:
authorRené Scharfe <l.s.r@web.de>2020-02-09 16:44:23 +0300
committerJunio C Hamano <gitster@pobox.com>2020-02-10 20:04:45 +0300
commita91cc7fad0d48984135abe2fb70c41db61b500c5 (patch)
treed6b5e82a62a48d7ba436bcaecf1c897ce449161d /strbuf.h
parentd0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 (diff)
strbuf: add and use strbuf_insertstr()
Add a function for inserting a C string into a strbuf. Use it throughout the source to get rid of magic string length constants and explicit strlen() calls. Like strbuf_addstr(), implement it as an inline function to avoid the implicit strlen() calls to cause runtime overhead. Helped-by: Taylor Blau <me@ttaylorr.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index bfa66569a4..aae7ac3a82 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -245,6 +245,18 @@ void strbuf_addchars(struct strbuf *sb, int c, size_t n);
void strbuf_insert(struct strbuf *sb, size_t pos, const void *, size_t);
/**
+ * Insert a NUL-terminated string to the given position of the buffer.
+ * The remaining contents will be shifted, not overwritten. It's an
+ * inline function to allow the compiler to resolve strlen() calls on
+ * constants at compile time.
+ */
+static inline void strbuf_insertstr(struct strbuf *sb, size_t pos,
+ const char *s)
+{
+ strbuf_insert(sb, pos, s, strlen(s));
+}
+
+/**
* Insert data to the given position of the buffer giving a printf format
* string. The contents will be shifted, not overwritten.
*/