• J
    strbuf_read(): skip unnecessary strbuf_grow() at eof · 3ebbd00c
    Jim Hill 提交于
    The loop in strbuf_read() uses xread() repeatedly while extending
    the strbuf until the call returns zero.  If the buffer is
    sufficiently large to begin with, this results in xread()
    returning the remainder of the file to the end (returning
    non-zero), the loop extending the strbuf, and then making another
    call to xread() to have it return zero.
    
    By using read_in_full(), we can tell when the read reached the end
    of file: when it returns less than was requested, it's eof.  This
    way we can avoid an extra iteration that allocates an extra 8kB
    that is never used.
    Signed-off-by: NJim Hill <gjthill@gmail.com>
    Reviewed-by: NJeff King <peff@peff.net>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    3ebbd00c
strbuf.c 11.6 KB