diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-09-03 19:17:50 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-09-03 19:17:50 -0700 |
commit | 8b2707101aa52d4da98becea0aa910de13768488 (patch) | |
tree | bd89341a787246d1dbb13a0d8260fb19c8c5af50 /strbuf.c | |
parent | Merge branch 'jk/long-error-messages' into maint (diff) | |
parent | strbuf_read(): skip unnecessary strbuf_grow() at eof (diff) | |
download | tgif-8b2707101aa52d4da98becea0aa910de13768488.tar.xz |
Merge branch 'jh/strbuf-read-use-read-in-full' into maint
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.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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); } |