Re: [PATCH 6/6] Replace all read_fd use with strbuf_read, and get rid of it.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 09, 2007 at 10:38:55PM +0000, Junio C Hamano wrote:
> Pierre Habouzit <madcoder@xxxxxxxxxx> writes:
> 
> >   This brings builtin-stripspace, builtin-tag and mktag to use strbufs.
> 
> One worry I have about this is that strbuf_read() only does the
> default allocation growth, while all of these callers used to
> have some guess as to what the initial allocation to avoid
> realloc should be.
> 
> Perhaps you would want to pre-grow the buffer between strbuf_init()
> and strbuf_read() calls?

  Well, I was pondering about extending strbuf_read() to take an extra
signed argument that would be the initial growth strbuf_read should
perform, used as a size hint. negative values would mean to deafault to
the default mechanism.

  Would you be more comfortable if I introduce such a change first ?
That way, if we have stat'ed the file we try to read first, we can
directly allocate the correct size.

  I also think about extending strbuf_init the same way (this time with
a size_t), and if the second argument is non zero, then it performs a
strbuf_grow(...) of that size, because we often have:

  strbuf_init(&sb);
  strbuf_grow(&sb, size_hint);

  and it's definitely better to read:

  strbuf_init(&sb, size_hint);


  I think I'll do that soon.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@xxxxxxxxxx
OOO                                                http://www.madism.org

Attachment: pgp6YCakMyorh.pgp
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux