summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:05 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:06 -0700
commit3b281d128180cd583db7c7b852909255ffd8f627 (patch)
treecd3e1919879fe2a3b2522e44058418169bb1e6ff /strbuf.c
parentff86faf2fa02bc21933c9e1dcc75c8d81b3e104a (diff)
parent3ebbd00cf3c5a7c6f90e2fed8adaf0c5145fb4ac (diff)
downloadgit-3b281d128180cd583db7c7b852909255ffd8f627.tar.gz
Merge branch 'jh/strbuf-read-use-read-in-full'
strbuf_read() used to have one extra iteration (and an unnecessary strbuf_grow() of 8kB), which was eliminated. * jh/strbuf-read-use-read-in-full: strbuf_read(): skip unnecessary strbuf_grow() at eof
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/strbuf.c b/strbuf.c
index cce5eed14a..29df55b1b0 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -364,19 +364,19 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
strbuf_grow(sb, hint ? hint : 8192);
for (;;) {
- ssize_t cnt;
+ ssize_t want = sb->alloc - sb->len - 1;
+ ssize_t got = read_in_full(fd, sb->buf + sb->len, want);
- cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
- if (cnt < 0) {
+ if (got < 0) {
if (oldalloc == 0)
strbuf_release(sb);
else
strbuf_setlen(sb, oldlen);
return -1;
}
- if (!cnt)
+ sb->len += got;
+ if (got < want)
break;
- sb->len += cnt;
strbuf_grow(sb, 8192);
}