Re: xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-04 Thread Jim Meyering
Paul Eggert <[EMAIL PROTECTED]> wrote: > Jim Meyering <[EMAIL PROTECTED]> writes: > >> - if (((size_t) -1) / 2 / s < n) >> + if ((2 * (((size_t) -1 - 1) / 3)) / s < n) > > That's not quite right. As an extreme case, suppose S is > SIZE_MAX/4 + 1 and N is 2. Then (2 * (((size_t) -1 - 1)

Re: xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-04 Thread Jim Meyering
Bruno Haible <[EMAIL PROTECTED]> wrote: > Jim Meyering wrote: >> I've just changed xalloc's x2nrealloc to do n = 3n/2, rather than n *= 2, > > Which means that the time needed for realloc() will grow by a factor of 1.7 > on average. If it matters - haven't measured it -, I would suggest to use >

Re: xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-03 Thread Paul Eggert
Jim Meyering <[EMAIL PROTECTED]> writes: > - if (((size_t) -1) / 2 / s < n) > + if ((2 * (((size_t) -1 - 1) / 3)) / s < n) That's not quite right. As an extreme case, suppose S is SIZE_MAX/4 + 1 and N is 2. Then (2 * (((size_t) -1 - 1) / 3)) / S evaluates to 2 and N will appear to be

Re: xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-02 Thread Andi Kleen
On Friday 02 February 2007 00:52, Jim Meyering wrote: > The length of the string being searched matters. More precisely, > it's the offsets (into the buffer being searched) of the beginning > and end of the match. I see. > I've just changed xalloc's x2nrealloc to do n = 3n/2, rather than n *= 2

Re: xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-01 Thread Bruno Haible
Jim Meyering wrote: > I've just changed xalloc's x2nrealloc to do n = 3n/2, rather than n *= 2, Which means that the time needed for realloc() will grow by a factor of 1.7 on average. If it matters - haven't measured it -, I would suggest to use - n = 2*n for n < 100, - n = 3*n/2 for n >

xalloc.h (x2nrealloc): Don't always double the buffer size.

2007-02-01 Thread Jim Meyering
For background, this thread started here: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/9581 Andi Kleen <[EMAIL PROTECTED]> wrote: >> [*] Can you even get a 2GB-long string into expr? > > At least on Linux you can't, the kernel limits arguments and environments > to 128K or so. There ar