- /* we've found a match, but now check to see
- * if last_i can hint at a better match */
- for (j++; j < (int) s->count && targets[j].t == t; j++) {
- int i2 = targets[j].i;
- if (i2 == last_i + 1) {
- if (sum != s->sums[i2].sum1) break;
- if (memcmp(sum2,s->sums[i2].sum2,s->s2length) != 0) break;
- /* we've found an adjacent match - the RLL coder
- * will be happy */
- i = i2;
- break;
- }
+ /* When updating in-place, the best possible match is
+ * one with an identical offset, so we prefer that over
+ * the following want_i optimization. */
+ if (updating_basis_file) {
+ do {
+ int32 i2 = targets[j].i;
+ if (s->sums[i2].offset != offset)
+ continue;
+ if (i2 != i) {
+ if (sum != s->sums[i2].sum1)
+ break;
+ if (memcmp(sum2, s->sums[i2].sum2,
+ s->s2length) != 0)
+ break;
+ i = i2;
+ }
+ /* This chunk was at the same offset on
+ * both the sender and the receiver. */
+ s->sums[i].flags |= SUMFLG_SAME_OFFSET;
+ goto set_want_i;
+ } while (++j < s->count && targets[j].t == t);