Add two additional offsets while trying to create a patch 99/272099/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 8 Mar 2022 10:52:32 +0000 (11:52 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 10 Mar 2022 14:43:25 +0000 (15:43 +0100)
Creating a patch with an offset score equal to 8 may take too long. On
the other hand for a value of 2 the resulting patch will consist of
multiple blocks, which can significantly increase the application time.
Therefore this commit adds two intermediate steps as a compromise
solution.

Change-Id: Id90beba4c4c89e20fb5f377f1499fb308e9f36a1

bsdiff/ss_bsdiff.c

index 209f2e9..0cef267 100755 (executable)
@@ -723,13 +723,16 @@ int MY_CDECL main(int argc, char *argv[])
 
        int ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 8);
 #ifdef TIME_LIMIT_CHECK
-       if (ret != 0) {
-               printf("Trying with offset score 2\n");
-               ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 2);
-       }
-       if (ret != 0) {
-               printf("Trying with offset score 0\n");
-               ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 0);
+       /*
+        * Creating a patch with an offset score equal to 8 may take too long. On
+        * the other hand for a value of 2 the resulting patch will consist of
+        * multiple blocks, which can significantly increase the application time.
+        * Therefore this commit adds two intermediate steps as a compromise
+        * solution.
+       */
+       for (int score = 6; score >= 0 && ret != 0; score-=2) {
+               printf("Trying with offset score %d\n", score);
+               ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, score);
        }
        if (ret != 0)
                err(1, "bsdiff fails to create delta within timelimit");