Skip to content

Commit 3bb55e8

Browse files
modocachegitster
authored andcommitted
strbuf: use _rtrim and _ltrim in strbuf_trim
strbuf_trim() strips whitespace from the end, then the beginning of a strbuf. Those operations are duplicated in strbuf_rtrim() and strbuf_ltrim(). Replace strbuf_trim() implementation with calls to strbuf_rtrim(), then strbuf_ltrim(). Signed-off-by: Brian Gesiak <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8779e1 commit 3bb55e8

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

strbuf.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
7878

7979
void strbuf_trim(struct strbuf *sb)
8080
{
81-
char *b = sb->buf;
82-
while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
83-
sb->len--;
84-
while (sb->len > 0 && isspace(*b)) {
85-
b++;
86-
sb->len--;
87-
}
88-
memmove(sb->buf, b, sb->len);
89-
sb->buf[sb->len] = '\0';
81+
strbuf_rtrim(sb);
82+
strbuf_ltrim(sb);
9083
}
9184
void strbuf_rtrim(struct strbuf *sb)
9285
{

0 commit comments

Comments
 (0)