OLD | NEW |
1 /* | 1 /* |
2 bsdiff.c -- Binary patch generator. | 2 bsdiff.c -- Binary patch generator. |
3 | 3 |
4 Copyright 2003 Colin Percival | 4 Copyright 2003 Colin Percival |
5 | 5 |
6 For the terms under which this work may be distributed, please see | 6 For the terms under which this work may be distributed, please see |
7 the adjoining file "LICENSE". | 7 the adjoining file "LICENSE". |
8 | 8 |
9 ChangeLog: | 9 ChangeLog: |
10 2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit | 10 2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit |
11 values throughout. | 11 values throughout. |
12 --Benjamin Smedberg <benjamin@smedbergs.us> | 12 --Benjamin Smedberg <benjamin@smedbergs.us> |
13 2005-05-18 - Use the same CRC algorithm as bzip2, and leverage the CRC table | 13 2005-05-18 - Use the same CRC algorithm as bzip2, and leverage the CRC table |
14 provided by libbz2. | 14 provided by libbz2. |
15 --Darin Fisher <darin@meer.net> | 15 --Darin Fisher <darin@meer.net> |
16 2007-11-14 - Changed to use Crc from Lzma library instead of Bzip library | 16 2007-11-14 - Changed to use Crc from Lzma library instead of Bzip library |
17 --Rahul Kuchhal | 17 --Rahul Kuchhal |
18 2009-03-31 - Change to use Streams. Added lots of comments. | 18 2009-03-31 - Change to use Streams. Added lots of comments. |
19 --Stephen Adams <sra@chromium.org> | 19 --Stephen Adams <sra@chromium.org> |
20 2010-05-26 - Use a paged array for V and I. The address space may be too | 20 2010-05-26 - Use a paged array for V and I. The address space may be too |
21 fragmented for these big arrays to be contiguous. | 21 fragmented for these big arrays to be contiguous. |
22 --Stephen Adams <sra@chromium.org> | 22 --Stephen Adams <sra@chromium.org> |
23 2015-08-03 - Extract qsufsort portion to a separate file. | 23 2015-08-03 - Extract qsufsort portion to a separate file. |
24 --Samuel Huang <huangs@chromium.org> | 24 --Samuel Huang <huangs@chromium.org> |
25 2015-08-12 - Interface change to qsufsort search(). | 25 2015-08-12 - Interface change to search(). |
26 --Samuel Huang <huangs@chromium.org> | 26 --Samuel Huang <huangs@chromium.org> |
27 */ | 27 */ |
28 | 28 |
29 #include "courgette/third_party/bsdiff/bsdiff.h" | 29 #include "courgette/third_party/bsdiff/bsdiff.h" |
30 | 30 |
31 #include <stddef.h> | 31 #include <stddef.h> |
32 #include <stdint.h> | 32 #include <stdint.h> |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #include <algorithm> | 34 #include <algorithm> |
35 | 35 |
36 #include "base/logging.h" | 36 #include "base/logging.h" |
37 #include "base/strings/string_util.h" | 37 #include "base/strings/string_util.h" |
38 #include "base/time/time.h" | 38 #include "base/time/time.h" |
39 | 39 |
40 #include "courgette/crc.h" | 40 #include "courgette/crc.h" |
41 #include "courgette/streams.h" | 41 #include "courgette/streams.h" |
| 42 #include "courgette/third_party/bsdiff/bsdiff_search.h" |
42 #include "courgette/third_party/bsdiff/paged_array.h" | 43 #include "courgette/third_party/bsdiff/paged_array.h" |
43 #include "courgette/third_party/bsdiff/qsufsort.h" | 44 #include "courgette/third_party/bsdiff/qsufsort.h" |
44 | 45 |
45 namespace courgette { | 46 namespace { |
| 47 |
| 48 using courgette::CalculateCrc; |
| 49 using courgette::PagedArray; |
| 50 using courgette::SinkStream; |
| 51 using courgette::SinkStreamSet; |
| 52 using courgette::SourceStream; |
| 53 using courgette::SourceStreamSet; |
| 54 |
| 55 } // namespace |
| 56 |
| 57 namespace bsdiff { |
46 | 58 |
47 static CheckBool WriteHeader(SinkStream* stream, MBSPatchHeader* header) { | 59 static CheckBool WriteHeader(SinkStream* stream, MBSPatchHeader* header) { |
48 bool ok = stream->Write(header->tag, sizeof(header->tag)); | 60 bool ok = stream->Write(header->tag, sizeof(header->tag)); |
49 ok &= stream->WriteVarint32(header->slen); | 61 ok &= stream->WriteVarint32(header->slen); |
50 ok &= stream->WriteVarint32(header->scrc32); | 62 ok &= stream->WriteVarint32(header->scrc32); |
51 ok &= stream->WriteVarint32(header->dlen); | 63 ok &= stream->WriteVarint32(header->dlen); |
52 return ok; | 64 return ok; |
53 } | 65 } |
54 | 66 |
55 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, | 67 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 int scan = 0; | 156 int scan = 0; |
145 int match_length = 0; | 157 int match_length = 0; |
146 | 158 |
147 while (scan < newsize) { | 159 while (scan < newsize) { |
148 int pos = 0; | 160 int pos = 0; |
149 int oldscore = 0; // Count of how many bytes of the current match at |scan| | 161 int oldscore = 0; // Count of how many bytes of the current match at |scan| |
150 // extend the match at |lastscan|. | 162 // extend the match at |lastscan|. |
151 | 163 |
152 scan += match_length; | 164 scan += match_length; |
153 for (int scsc = scan; scan < newsize; ++scan) { | 165 for (int scsc = scan; scan < newsize; ++scan) { |
154 match_length = qsuf::search<PagedArray<int>&>( | 166 match_length = search<PagedArray<int>&>( |
155 I, old, oldsize, newbuf + scan, newsize - scan, &pos); | 167 I, old, oldsize, newbuf + scan, newsize - scan, &pos); |
156 | 168 |
157 for (; scsc < scan + match_length; scsc++) | 169 for (; scsc < scan + match_length; scsc++) |
158 if ((scsc + lastoffset < oldsize) && | 170 if ((scsc + lastoffset < oldsize) && |
159 (old[scsc + lastoffset] == newbuf[scsc])) | 171 (old[scsc + lastoffset] == newbuf[scsc])) |
160 oldscore++; | 172 oldscore++; |
161 | 173 |
162 if ((match_length == oldscore) && (match_length != 0)) | 174 if ((match_length == oldscore) && (match_length != 0)) |
163 break; // Good continuing match, case (1) | 175 break; // Good continuing match, case (1) |
164 if (match_length > oldscore + 8) | 176 if (match_length > oldscore + 8) |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 << " (skips: " << diff_skips_length << ")" | 321 << " (skips: " << diff_skips_length << ")" |
310 << " extra bytes: " << extra_bytes_length | 322 << " extra bytes: " << extra_bytes_length |
311 << "\nUncompressed bsdiff patch size " | 323 << "\nUncompressed bsdiff patch size " |
312 << patch_stream->Length() - initial_patch_stream_length | 324 << patch_stream->Length() - initial_patch_stream_length |
313 << "\nEnd bsdiff " | 325 << "\nEnd bsdiff " |
314 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); | 326 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); |
315 | 327 |
316 return OK; | 328 return OK; |
317 } | 329 } |
318 | 330 |
319 } // namespace courgette | 331 } // namespace bsdiff |
OLD | NEW |