pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:217:    memcpy( io->buffer, old, io->len );    io_unlink_external_storage(io);    }    }       PMOD_EXPORT unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )    ATTRIBUTE((noclone,noinline));    PMOD_EXPORT unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )    {    if( bytes && io->len+bytes < io->len ) -  Pike_error("Too large buffer, can not have more than %lu bytes.", +  Pike_error("Buffer too large, can not have more than %lu bytes.",    (size_t)-1);    -  -  io_ensure_unlocked(io); +     io_ensure_malloced(io, bytes);       /*    * It is actually not certain that checking this is a good idea.    *    * The reason being that if the current buffer size is very small    * (io_len(io)) and the bytes added is large and there is an    * offset, it makes sense to move now when we do not have to copy    * as much.    *    */ -  if( UNLIKELY((force && io->offset) +  if( LIKELY(!io->locked) +  && UNLIKELY((force && io->offset)    || (io_len(io) && io->offset > io->allocated / 2)) )    {    /* more than 50% of the buffer is available before the read pointer,    * and we can discard that data. Move the data to the beginning, making    * room for more data.    */    io_discard_bufstart(io);    }       if( UNLIKELY(io->len + bytes > io->allocated) )    {    /* Actually grow the buffer. */    size_t growth =    (io->allocated>>1) +    (io->allocated>>3);/* io->allocated * 0.625 */    -  +  io_ensure_unlocked(io); +     if( growth < bytes )    growth = bytes + (bytes>>1);       if( io->allocated + growth < io->allocated )    {    growth = bytes+1;    if( io->allocated + growth < io->allocated )    Pike_error("Overflow in buffer size calculations.\n");    }    io->buffer = xrealloc( io->buffer, io->allocated + growth );