bsdiff-portable

A more portable version of Colin Percival's bsdiff
git clone git://git.sgregoratto.me/bsdiff-portable
Log | Files | Refs | README | LICENSE

commit 43c561230cff795381ea1a8377b7f0514da51a72
parent a43eb860491079d2587b6cda6bb567862cfbaeaa
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Thu, 24 Sep 2020 15:13:14 +1000

bsdiff: move patch writing out of main loop end

Diffstat:
Mbsdiff.c | 33+++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/bsdiff.c b/bsdiff.c @@ -147,7 +147,7 @@ main(int argc, char **argv) filelen += 32; /* Compute the differences, writing ctrl as we go */ - scan = len = lastscan = lastpos = lastoffset = 0; + scan = len = lenf = lenb = lastscan = pos = lastpos = lastoffset = 0; while (scan < newsize) { oldscore = 0; @@ -216,31 +216,24 @@ main(int argc, char **argv) lenf += lens - overlap; lenb -= lens; } - - for (i = 0; i < lenf; i++) - db[dblen + i] = - new[lastscan + i] - old[lastpos + i]; - for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++) - eb[eblen + i] = new[lastscan + lenf + i]; - - dblen += lenf; - eblen += (scan - lenb) - (lastscan + lenf); - - offtout(lenf, buf); - offtout((scan - lenb) - (lastscan + lenf), buf + 8); - offtout((pos - lenb) - (lastpos + lenf), buf + 16); - filelen += bz_write(pf, buf, sizeof(buf)); - - lastscan = scan - lenb; - lastpos = pos - lenb; - lastoffset = pos - scan; } } /* Compute the size of the blocks and write them */ + offtout(lenf, buf); + offtout((scan - lenb) - (lastscan + lenf), buf + 8); + offtout((pos - lenb) - (lastpos + lenf), buf + 16); + filelen += bz_write(pf, buf, sizeof(buf)); header.ctrl_block_len = filelen - 32; + + for (i = 0; i < lenf; i++) + db[dblen + i] = new[lastscan + i] - old[lastpos + i]; + dblen += lenf; filelen += bz_write(pf, db, dblen); + header.diff_block_len = filelen - (header.ctrl_block_len + 32); - header.diff_block_len = filelen - (header.ctrl_block_len + 32), + for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++) + eb[eblen + i] = new[lastscan + lenf + i]; + eblen += (scan - lenb) - (lastscan + lenf); bz_write(pf, eb, eblen); /* Seek to the beginning, write the header, and close the file */