Skip to content

Commit 8b27071

Browse files
committed
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
2 parents 6c0850f + 3ebbd00 commit 8b27071

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

strbuf.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,19 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, size_t hint)
364364

365365
strbuf_grow(sb, hint ? hint : 8192);
366366
for (;;) {
367-
ssize_t cnt;
367+
ssize_t want = sb->alloc - sb->len - 1;
368+
ssize_t got = read_in_full(fd, sb->buf + sb->len, want);
368369

369-
cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
370-
if (cnt < 0) {
370+
if (got < 0) {
371371
if (oldalloc == 0)
372372
strbuf_release(sb);
373373
else
374374
strbuf_setlen(sb, oldlen);
375375
return -1;
376376
}
377-
if (!cnt)
377+
sb->len += got;
378+
if (got < want)
378379
break;
379-
sb->len += cnt;
380380
strbuf_grow(sb, 8192);
381381
}
382382

0 commit comments

Comments
 (0)