FreeBSD/contrib/subversion/subversion/libsvn_subr/packed_data.c
/* Ensure that STREAM contains at least one item in its buffer.
 */
Ensure that STREAM contains at least one item in its buffer.
Ensure that STREAM contains at least one item in its buffer .
static void
svn_packed__data_fill_buffer(svn_packed__int_stream_t *stream)
{
  packed_int_private_t *private_data = stream->private_data;
  apr_size_t i;
  apr_size_t end = MIN(SVN__PACKED_DATA_BUFFER_SIZE,
                       private_data->item_count);
  if (stream->buffer_used)
    return;
  if (private_data->current_substream)
    for (i = end; i > 0; --i)
      {
        packed_int_private_t *current_private_data
          = private_data->current_substream->private_data;
        stream->buffer[i-1]
          = svn_packed__get_uint(private_data->current_substream);
        private_data->current_substream = current_private_data->next;
      }
  else
    {
      unsigned char local_buffer[10 * SVN__PACKED_DATA_BUFFER_SIZE];
      unsigned char *p;
      unsigned char *start;
      apr_size_t packed_read;
      if (private_data->packed->len < sizeof(local_buffer))
        {
          apr_size_t trail = sizeof(local_buffer) - private_data->packed->len;
          memcpy(local_buffer,
                 private_data->packed->data,
                 private_data->packed->len);
          memset(local_buffer + private_data->packed->len, 0, MIN(trail, end));
          p = local_buffer;
        }
      else
        p = (unsigned char *)private_data->packed->data;
      start = p;
      for (i = end; i > 0; --i)
        p = read_packed_uint_body(p, &stream->buffer[i-1]);
      packed_read = p - start;
      private_data->packed->data += packed_read;
      private_data->packed->len -= packed_read;
      private_data->packed->blocksize -= packed_read;
      if (private_data->diff)
        {
          apr_uint64_t last_value = private_data->last_value;
          for (i = end; i > 0; --i)
            {
              last_value += unmap_uint(stream->buffer[i-1]);
              stream->buffer[i-1] = last_value;
            }
          private_data->last_value = last_value;
        }
      if (!private_data->diff && private_data->is_signed)
        for (i = 0; i < end; ++i)
          stream->buffer[i] = unmap_uint(stream->buffer[i]);
    }
  stream->buffer_used = end;
  private_data->item_count -= end;
}
static void svn_packed__data_fill_buffer ( svn_packed__int_stream_t * stream ) { packed_int_private_t * private_data = stream -> private_data ; apr_size_t i ; apr_size_t end = MIN ( SVN__PACKED_DATA_BUFFER_SIZE , private_data -> item_count ) ; if ( stream -> buffer_used ) return ; if ( private_data -> current_substream ) for ( i = end ; i > 0 ; -- i ) { packed_int_private_t * current_private_data = private_data -> current_substream -> private_data ; stream -> buffer [ i - 1 ] = svn_packed__get_uint ( private_data -> current_substream ) ; private_data -> current_substream = current_private_data -> next ; } else { unsigned char local_buffer [ 10 * SVN__PACKED_DATA_BUFFER_SIZE ] ; unsigned char * p ; unsigned char * start ; apr_size_t packed_read ; if ( private_data -> packed -> len < sizeof ( local_buffer ) ) { apr_size_t trail = sizeof ( local_buffer ) - private_data -> packed -> len ; memcpy ( local_buffer , private_data -> packed -> data , private_data -> packed -> len ) ; memset ( local_buffer + private_data -> packed -> len , 0 , MIN ( trail , end ) ) ; p = local_buffer ; } else p = ( unsigned char * ) private_data -> packed -> data ; start = p ; for ( i = end ; i > 0 ; -- i ) p = read_packed_uint_body ( p , & stream -> buffer [ i - 1 ] ) ; packed_read = p - start ; private_data -> packed -> data += packed_read ; private_data -> packed -> len -= packed_read ; private_data -> packed -> blocksize -= packed_read ; if ( private_data -> diff ) { apr_uint64_t last_value = private_data -> last_value ; for ( i = end ; i > 0 ; -- i ) { last_value += unmap_uint ( stream -> buffer [ i - 1 ] ) ; stream -> buffer [ i - 1 ] = last_value ; } private_data -> last_value = last_value ; } if ( ! private_data -> diff && private_data -> is_signed ) for ( i = 0 ; i < end ; ++ i ) stream -> buffer [ i ] = unmap_uint ( stream -> buffer [ i ] ) ; } stream -> buffer_used = end ; private_data -> item_count -= end ; }
Ensure that STREAM contains at least one item in its buffer.
Ensure that STREAM contains at least one item in its buffer .
/* in case, some user calls us explicitly without a good reason ... */ /* can we get data from the sub-streams or do we have to decode it from
     our local packed container? */ /* use this local buffer only if the packed data is shorter than this.
         The goal is that read_packed_uint_body doesn't need check for
         overflows. */ /* unpack numbers */ /* adjust remaining packed data buffer */ /* undeltify numbers, if configured */ /* handle signed values, if configured and not handled already */