376
376
#define MAX_OP_SIZE (5 + 5 + 1 + RABIN_WINDOW + 7)
379
create_delta(struct delta_index **indexes,
380
unsigned int num_indexes,
379
create_delta(const struct delta_index *index,
381
380
const void *trg_buf, unsigned long trg_size,
382
381
unsigned long *delta_size, unsigned long max_size)
384
unsigned int i, j, outpos, outsize, moff, msize, val;
385
const struct delta_index *index;
383
unsigned int i, outpos, outsize, moff, msize, val;
386
384
const struct source_info *msource;
388
386
const unsigned char *ref_data, *ref_top, *data, *top;
456
447
/* Shift the window by one byte. */
457
448
val ^= U[data[-RABIN_WINDOW]];
458
449
val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT];
459
for (j = 0; j < num_indexes; ++j) {
461
i = val & index->hash_mask;
462
/* TODO: When using multiple indexes like this, the hash tables
463
* mapping val => index_entry become less efficient.
464
* You end up getting a lot more collisions in the hash,
465
* which doesn't actually lead to a entry->val match.
450
i = val & index->hash_mask;
451
/* TODO: When using multiple indexes like this, the hash tables
452
* mapping val => index_entry become less efficient.
453
* You end up getting a lot more collisions in the hash,
454
* which doesn't actually lead to a entry->val match.
456
for (entry = index->hash[i]; entry < index->hash[i+1];
458
const unsigned char *ref;
459
const unsigned char *src;
460
unsigned int ref_size;
461
if (entry->val != val)
465
ref_data = entry->src->buf;
466
ref_top = ref_data + entry->src->size;
467
ref_size = ref_top - ref;
468
/* ref_size is the longest possible match that we could make
469
* here. If ref_size <= msize, then we know that we cannot
470
* match more bytes with this location that we have already
467
for (entry = index->hash[i]; entry < index->hash[i+1];
469
const unsigned char *ref;
470
const unsigned char *src;
471
unsigned int ref_size;
472
if (entry->val != val)
476
ref_data = entry->src->buf;
477
ref_top = ref_data + entry->src->size;
478
ref_size = ref_top - ref;
479
/* ref_size is the longest possible match that we could make
480
* here. If ref_size <= msize, then we know that we cannot
481
* match more bytes with this location that we have already
484
if (ref_size > top - src)
485
ref_size = top - src;
486
if (ref_size <= msize)
473
if (ref_size > top - src)
474
ref_size = top - src;
475
if (ref_size <= msize)
477
/* See how many bytes actually match at this location. */
478
while (ref_size-- && *src++ == *ref)
480
if (msize < ref - entry->ptr) {
481
/* this is our best match so far */
482
msize = ref - entry->ptr;
483
msource = entry->src;
484
moff = entry->ptr - ref_data;
485
if (msize >= 4096) /* good enough */
488
/* See how many bytes actually match at this location. */
489
while (ref_size-- && *src++ == *ref)
491
if (msize < ref - entry->ptr) {
492
/* this is our best match so far */
493
msize = ref - entry->ptr;
494
msource = entry->src;
495
moff = entry->ptr - ref_data;
496
if (msize >= 4096) /* good enough */