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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:154:    if( pos > io_len( io ) )    return -1;    switch( io->buffer[io->offset+pos] )    {    SPACECASE8    return 1;    }    return 0;    }    -  static void io_trim( Buffer *io ) +  static void io_discard_bufstart( Buffer *io )    { -  if( !io->locked && io->malloced && (io->offset > 64 || io->len > 64) ) +  if ( LIKELY(!io->locked_move) )    { -  if( !io->locked_move && io->offset > 64 && io->offset > io_len(io)) -  { +     memmove( io->buffer, io_read_pointer(io), io_len(io) );    io->len -= io->offset;    io->num_move++;    io->offset = 0;    } -  +  } +  +  static void io_trim( Buffer *io ) +  { +  if( !io->locked && io->malloced && (io->offset > 64 || io->len > 64) ) +  { +  if( io->offset > 64 && io->offset > io_len(io) ) +  io_discard_bufstart(io); +     if( io->len > 64 && ((io->allocated > (io->len)*(1.0+io->max_waste))))    {    void *new_ptr = xrealloc( io->buffer, io->len );    if( !new_ptr )    Pike_error(msg_out_of_mem_2, io->len);       io->buffer = new_ptr;    io->num_malloc++;    io->allocated = io->len;    }
pike.git/src/modules/_Stdio/buffer.cmod:238:       /*    * 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( LIKELY(!io->locked_move) ) +  if( UNLIKELY(force && io->offset +  || io_len(io) && io->offset > io->allocated / 2) )    { -  if( 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.    */ -  memmove( io->buffer, io_read_pointer(io), io_len(io) ); -  io->num_move++; -  io->len -= io->offset; -  io->offset = 0; +  io_discard_bufstart(io);    } -  } +        if( UNLIKELY(io->len + bytes > io->allocated) )    {    /* Actually grow the buffer. */    void *new_ptr;    size_t growth =    (io->allocated>>1) +    (io->allocated>>3);/* io->allocated * 0.625 */       if( growth < bytes )