diff options
-rwxr-xr-x | bsdiff/ss_bsdiff.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bsdiff/ss_bsdiff.c b/bsdiff/ss_bsdiff.c index b153a73..76fbe41 100755 --- a/bsdiff/ss_bsdiff.c +++ b/bsdiff/ss_bsdiff.c @@ -362,7 +362,13 @@ int Function(int offset_oldscore) lastoffset = 0; while (scan < end) { oldscore = 0; + size_t prev_len; + uint64_t prev_pos, prev_oldscore; + int num_less_than_eight = 0; for (scsc = scan += len; scan < end; scan++) { + prev_len = len; + prev_oldscore = oldscore; + prev_pos = pos; len = search(data.I, data.old, data.oldsize, data.new[thread_num] + scan, end - scan, len, data.oldsize, &pos); // Passing parameter as len instead of 0 for ramdisk.img etc taking long time @@ -389,6 +395,24 @@ int Function(int offset_oldscore) if ((scan + lastoffset < data.oldsize) && (data.old[scan + lastoffset] == data.new[thread_num][scan])) oldscore--; + + /* + * Modification created by Thieu Le <thieule@chromium.org> + * which speeds up patch generation time in situations + * where large blocks of data differ by less than 8 bytes. + * https://android.googlesource.com/platform/external/bsdiff/+/d172820cb8b4513478f0db5546d6e4d388adc1a7 + */ + const size_t fuzz = 8; + if (prev_len - fuzz <= len && len <= prev_len && + prev_oldscore - fuzz <= oldscore && + prev_pos <= pos && pos <= prev_pos + fuzz && + oldscore <= len && len <= oldscore + fuzz) { + num_less_than_eight++; + } else { + num_less_than_eight = 0; + } + if (num_less_than_eight > 100) break; + }; if ((len != oldscore) || (scan == end)) { s = 0; |