summaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-20 00:42:12 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-20 23:17:40 -0700
commitc76689df6c64a1e987bd779bd71a2042b5131fb9 (patch)
tree22f810d6b67ed4bd03bfafb244eb9e6012502476 /strbuf.h
parent19247e5510279f018f8358a72b38cc5aa62fac8a (diff)
downloadgit-c76689df6c64a1e987bd779bd71a2042b5131fb9.tar.gz
strbuf API additions and enhancements.
Add strbuf_remove, change strbuf_insert: As both are special cases of strbuf_splice, implement them as such. gcc is able to do the math and generate almost optimal code this way. Add strbuf_swap: Exchange the values of its arguments. Use it in fast-import.c Also fix spacing issues in strbuf.h Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/strbuf.h b/strbuf.h
index b2cbd976f4..567e2d17d1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -55,15 +55,20 @@ extern void strbuf_release(struct strbuf *);
extern void strbuf_reset(struct strbuf *);
extern char *strbuf_detach(struct strbuf *);
extern void strbuf_attach(struct strbuf *, void *, size_t, size_t);
+static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) {
+ struct strbuf tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
/*----- strbuf size related -----*/
static inline size_t strbuf_avail(struct strbuf *sb) {
- return sb->alloc ? sb->alloc - sb->len - 1 : 0;
+ return sb->alloc ? sb->alloc - sb->len - 1 : 0;
}
static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
- assert (len < sb->alloc);
- sb->len = len;
- sb->buf[len] = '\0';
+ assert (len < sb->alloc);
+ sb->len = len;
+ sb->buf[len] = '\0';
}
extern void strbuf_grow(struct strbuf *, size_t);
@@ -78,12 +83,12 @@ static inline void strbuf_addch(struct strbuf *sb, int c) {
sb->buf[sb->len] = '\0';
}
-/* inserts after pos, or appends if pos >= sb->len */
extern void strbuf_insert(struct strbuf *, size_t pos, const void *, size_t);
+extern void strbuf_remove(struct strbuf *, size_t pos, size_t len);
/* splice pos..pos+len with given data */
extern void strbuf_splice(struct strbuf *, size_t pos, size_t len,
- const void *, size_t);
+ const void *, size_t);
extern void strbuf_add(struct strbuf *, const void *, size_t);
static inline void strbuf_addstr(struct strbuf *sb, const char *s) {