diff options
author | Pierre Habouzit <madcoder@debian.org> | 2007-09-20 00:42:12 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-20 23:17:40 -0700 |
commit | c76689df6c64a1e987bd779bd71a2042b5131fb9 (patch) | |
tree | 22f810d6b67ed4bd03bfafb244eb9e6012502476 /strbuf.c | |
parent | 19247e5510279f018f8358a72b38cc5aa62fac8a (diff) | |
download | git-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.c')
-rw-r--r-- | strbuf.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -50,16 +50,6 @@ void strbuf_rtrim(struct strbuf *sb) sb->buf[sb->len] = '\0'; } -void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) -{ - strbuf_grow(sb, len); - if (pos > sb->len) - die("`pos' is too far after the end of the buffer"); - memmove(sb->buf + pos + len, sb->buf + pos, sb->len - pos); - memcpy(sb->buf + pos, data, len); - strbuf_setlen(sb, sb->len + len); -} - void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, const void *data, size_t dlen) { @@ -79,6 +69,16 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, strbuf_setlen(sb, sb->len + dlen - len); } +void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) +{ + strbuf_splice(sb, pos, 0, data, len); +} + +void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) +{ + strbuf_splice(sb, pos, len, NULL, 0); +} + void strbuf_add(struct strbuf *sb, const void *data, size_t len) { strbuf_grow(sb, len); |