summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>2022-08-23 16:18:57 +0200
committerKarol Lewandowski <k.lewandowsk@samsung.com>2022-08-23 14:48:43 +0000
commit143447ad7874296bf824d47b5cd2f4168dfee871 (patch)
tree122486711102091ea17a136300f4036bf7519d35
parent5c6c4b68e569037d4548ee1f2eae39033cd5f9ca (diff)
downloadlibtota-143447ad7874296bf824d47b5cd2f4168dfee871.tar.gz
libtota-143447ad7874296bf824d47b5cd2f4168dfee871.tar.bz2
libtota-143447ad7874296bf824d47b5cd2f4168dfee871.zip
ss_bsdiff: Fix to speed up patch generation
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. This change originates from: https://android.googlesource.com/platform/external/bsdiff/+/d172820cb8b4513478f0db5546d6e4d388adc1a7 Change-Id: Iee52b3d3e469ab0850c22bb6858beb7654c229d8
-rwxr-xr-xbsdiff/ss_bsdiff.c24
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;