FreeBSD/contrib/subversion/subversion/libsvn_delta/text_delta.c
/* Insert a delta op into a delta window. */
Insert a delta op into a delta window.
Insert a delta op into a delta window .
void
svn_txdelta__insert_op(svn_txdelta__ops_baton_t *build_baton,
                       enum svn_delta_action opcode,
                       apr_size_t offset,
                       apr_size_t length,
                       const char *new_data,
                       apr_pool_t *pool)
{
  svn_txdelta_op_t *op;
  if (build_baton->num_ops > 0)
    {
      op = &build_baton->ops[build_baton->num_ops - 1];
      if (op->action_code == opcode
          && (opcode == svn_txdelta_new
              || op->offset + op->length == offset))
        {
          op->length += length;
          if (opcode == svn_txdelta_new)
            svn_stringbuf_appendbytes(build_baton->new_data,
                                      new_data, length);
          return;
        }
    }
  if (build_baton->num_ops == build_baton->ops_size)
    {
      svn_txdelta_op_t *const old_ops = build_baton->ops;
      int const new_ops_size = (build_baton->ops_size == 0
                                ? 16 : 2 * build_baton->ops_size);
      build_baton->ops =
        apr_palloc(pool, new_ops_size * sizeof(*build_baton->ops));
      if (old_ops)
        memcpy(build_baton->ops, old_ops,
               build_baton->ops_size * sizeof(*build_baton->ops));
      build_baton->ops_size = new_ops_size;
    }
  op = &build_baton->ops[build_baton->num_ops];
  switch (opcode)
    {
    case svn_txdelta_source:
      ++build_baton->src_ops;
    case svn_txdelta_target:
      op->action_code = opcode;
      op->offset = offset;
      op->length = length;
      break;
    case svn_txdelta_new:
      op->action_code = opcode;
      op->offset = build_baton->new_data->len;
      op->length = length;
      svn_stringbuf_appendbytes(build_baton->new_data, new_data, length);
      break;
    default:
      assert(!"unknown delta op.");
    }
  ++build_baton->num_ops;
}
void svn_txdelta__insert_op ( svn_txdelta__ops_baton_t * build_baton , enum svn_delta_action opcode , apr_size_t offset , apr_size_t length , const char * new_data , apr_pool_t * pool ) { svn_txdelta_op_t * op ; if ( build_baton -> num_ops > 0 ) { op = & build_baton -> ops [ build_baton -> num_ops - 1 ] ; if ( op -> action_code == opcode && ( opcode == svn_txdelta_new || op -> offset + op -> length == offset ) ) { op -> length += length ; if ( opcode == svn_txdelta_new ) svn_stringbuf_appendbytes ( build_baton -> new_data , new_data , length ) ; return ; } } if ( build_baton -> num_ops == build_baton -> ops_size ) { svn_txdelta_op_t * const old_ops = build_baton -> ops ; int const new_ops_size = ( build_baton -> ops_size == 0 ? 16 : 2 * build_baton -> ops_size ) ; build_baton -> ops = apr_palloc ( pool , new_ops_size * sizeof ( * build_baton -> ops ) ) ; if ( old_ops ) memcpy ( build_baton -> ops , old_ops , build_baton -> ops_size * sizeof ( * build_baton -> ops ) ) ; build_baton -> ops_size = new_ops_size ; } op = & build_baton -> ops [ build_baton -> num_ops ] ; switch ( opcode ) { case svn_txdelta_source : ++ build_baton -> src_ops ; case svn_txdelta_target : op -> action_code = opcode ; op -> offset = offset ; op -> length = length ; break ; case svn_txdelta_new : op -> action_code = opcode ; op -> offset = build_baton -> new_data -> len ; op -> length = length ; svn_stringbuf_appendbytes ( build_baton -> new_data , new_data , length ) ; break ; default : assert ( ! " " ) ; } ++ build_baton -> num_ops ; }
Insert a delta op into a delta window.
Insert a delta op into a delta window .
/* Check if this op can be merged with the previous op. The delta
     combiner sometimes generates such ops, and this is the obvious
     place to make the check. */ /* Create space for the new op. */ /* Copy any existing ops into the new array */ /* Insert the op. svn_delta_source and svn_delta_target are
     just inserted. For svn_delta_new, the new data must be
     copied into the window. */ /*** FALLTHRU ***/