Skip to content

Commit 1a57dc1

Browse files
committed
Well, the virtual movement doesn't work - the algorithm really worked only with a fixed chunk size. Now the only chance we have is to allocate an appropriately sized buffer, and work through it directly. This makes things easier, and will make things work \!
1 parent 28263c9 commit 1a57dc1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

_delta_apply.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
620620
assert(tsi->num_chunks);
621621

622622
typedef struct {
623-
int bofs; // byte-offset of delta stream
623+
uint bofs; // byte-offset of delta stream
624624
uint dofs; // delta stream offset relative to tsi->cstart
625625
} OffsetInfo;
626626

@@ -631,7 +631,8 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
631631
}
632632

633633
OffsetInfo* pofs = offset_array;
634-
int num_addbytes = 0;
634+
uint num_addbytes = 0;
635+
int bytes = 0;
635636
uint dofs = 0;
636637

637638
const uchar* data = TSI_first(tsi);
@@ -658,15 +659,16 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
658659

659660
// offset the next chunk by the amount of chunks in the slice
660661
// - N, because we replace our own chunk's bytes
661-
num_addbytes += DIV_count_slice_bytes(div, dc.so, dc.ts) - (data - prev_data);
662+
bytes = DIV_count_slice_bytes(div, dc.so, dc.ts) - (data - prev_data);
663+
// if we shrink in size, compensate this by moving the start virtually
664+
//
665+
if (bytes < 0){
666+
fprintf(stderr, "hit negative bytes: %i\n", bytes);
667+
tsi->cstart += abs(bytes);
668+
}
669+
num_addbytes += abs(bytes);
662670
}
663671

664-
/*
665-
uint i = 0;
666-
for (; i < tsi->num_chunks; i++){
667-
fprintf(stderr, "%i: bofs: %i, dofs: %i\n", i, offset_array[i].bofs, offset_array[i].dofs);
668-
}
669-
*/
670672
assert(DC_rbound(&dc) == tsi->target_size);
671673

672674

@@ -701,8 +703,8 @@ bool DIV_connect_with_base(ToplevelStreamInfo* tsi, DeltaInfoVector* div)
701703

702704
// Copy Chunks - target offset is determined by their location and size
703705
// hence it doesn't need specific adjustment
704-
// -1 chunks because we overwrite our own chunk ( by not copying it )
705706
num_addchunks += DIV_copy_slice_to(div, ds + cpofs->bofs, dc.so, dc.ts);
707+
// -1 chunks because we overwrite our own chunk ( by not copying it )
706708
num_addchunks -= 1;
707709
}
708710

0 commit comments

Comments
 (0)