| OLD | NEW |
| 1 // Copyright 2003, 2004 Colin Percival | 1 // Copyright 2003, 2004 Colin Percival |
| 2 // All rights reserved | 2 // All rights reserved |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted providing that the following conditions | 5 // modification, are permitted providing that the following conditions |
| 6 // are met: | 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright | 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright | 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the | 10 // notice, this list of conditions and the following disclaimer in the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // --Stephen Adams <sra@chromium.org> | 41 // --Stephen Adams <sra@chromium.org> |
| 42 // 2015-08-03 - Extract qsufsort portion to a separate file. | 42 // 2015-08-03 - Extract qsufsort portion to a separate file. |
| 43 // --Samuel Huang <huangs@chromium.org> | 43 // --Samuel Huang <huangs@chromium.org> |
| 44 // 2015-08-12 - Interface change to search(). | 44 // 2015-08-12 - Interface change to search(). |
| 45 // --Samuel Huang <huangs@chromium.org> | 45 // --Samuel Huang <huangs@chromium.org> |
| 46 | 46 |
| 47 // Copyright 2016 The Chromium Authors. All rights reserved. | 47 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 48 // Use of this source code is governed by a BSD-style license that can be | 48 // Use of this source code is governed by a BSD-style license that can be |
| 49 // found in the LICENSE file. | 49 // found in the LICENSE file. |
| 50 | 50 |
| 51 | |
| 52 #include "courgette/third_party/bsdiff/bsdiff.h" | 51 #include "courgette/third_party/bsdiff/bsdiff.h" |
| 53 | 52 |
| 54 #include <stddef.h> | 53 #include <stddef.h> |
| 55 #include <stdint.h> | 54 #include <stdint.h> |
| 56 #include <stdlib.h> | 55 #include <stdlib.h> |
| 57 #include <algorithm> | 56 #include <algorithm> |
| 58 | 57 |
| 59 #include "base/logging.h" | 58 #include "base/logging.h" |
| 60 #include "base/strings/string_util.h" | 59 #include "base/strings/string_util.h" |
| 61 #include "base/time/time.h" | 60 #include "base/time/time.h" |
| 62 | 61 |
| 63 #include "courgette/crc.h" | 62 #include "courgette/crc.h" |
| 64 #include "courgette/streams.h" | 63 #include "courgette/streams.h" |
| 64 #include "courgette/third_party/bsdiff/bsdiff_search.h" |
| 65 #include "courgette/third_party/bsdiff/paged_array.h" | 65 #include "courgette/third_party/bsdiff/paged_array.h" |
| 66 #include "courgette/third_party/bsdiff/qsufsort.h" | 66 #include "courgette/third_party/bsdiff/qsufsort.h" |
| 67 | 67 |
| 68 namespace courgette { | 68 namespace courgette { |
| 69 | 69 |
| 70 static CheckBool WriteHeader(SinkStream* stream, MBSPatchHeader* header) { | 70 static CheckBool WriteHeader(SinkStream* stream, MBSPatchHeader* header) { |
| 71 bool ok = stream->Write(header->tag, sizeof(header->tag)); | 71 bool ok = stream->Write(header->tag, sizeof(header->tag)); |
| 72 ok &= stream->WriteVarint32(header->slen); | 72 ok &= stream->WriteVarint32(header->slen); |
| 73 ok &= stream->WriteVarint32(header->scrc32); | 73 ok &= stream->WriteVarint32(header->scrc32); |
| 74 ok &= stream->WriteVarint32(header->dlen); | 74 ok &= stream->WriteVarint32(header->dlen); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 int scan = 0; | 167 int scan = 0; |
| 168 int match_length = 0; | 168 int match_length = 0; |
| 169 | 169 |
| 170 while (scan < newsize) { | 170 while (scan < newsize) { |
| 171 int pos = 0; | 171 int pos = 0; |
| 172 int oldscore = 0; // Count of how many bytes of the current match at |scan| | 172 int oldscore = 0; // Count of how many bytes of the current match at |scan| |
| 173 // extend the match at |lastscan|. | 173 // extend the match at |lastscan|. |
| 174 | 174 |
| 175 scan += match_length; | 175 scan += match_length; |
| 176 for (int scsc = scan; scan < newsize; ++scan) { | 176 for (int scsc = scan; scan < newsize; ++scan) { |
| 177 match_length = qsuf::search<PagedArray<int>&>( | 177 match_length = courgette::search<PagedArray<int>&>( |
| 178 I, old, oldsize, newbuf + scan, newsize - scan, &pos); | 178 I, old, oldsize, newbuf + scan, newsize - scan, &pos); |
| 179 | 179 |
| 180 for (; scsc < scan + match_length; scsc++) | 180 for (; scsc < scan + match_length; scsc++) |
| 181 if ((scsc + lastoffset < oldsize) && | 181 if ((scsc + lastoffset < oldsize) && |
| 182 (old[scsc + lastoffset] == newbuf[scsc])) | 182 (old[scsc + lastoffset] == newbuf[scsc])) |
| 183 oldscore++; | 183 oldscore++; |
| 184 | 184 |
| 185 if ((match_length == oldscore) && (match_length != 0)) | 185 if ((match_length == oldscore) && (match_length != 0)) |
| 186 break; // Good continuing match, case (1) | 186 break; // Good continuing match, case (1) |
| 187 if (match_length > oldscore + 8) | 187 if (match_length > oldscore + 8) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 << " extra bytes: " << extra_bytes_length | 333 << " extra bytes: " << extra_bytes_length |
| 334 << "\nUncompressed bsdiff patch size " | 334 << "\nUncompressed bsdiff patch size " |
| 335 << patch_stream->Length() - initial_patch_stream_length | 335 << patch_stream->Length() - initial_patch_stream_length |
| 336 << "\nEnd bsdiff " | 336 << "\nEnd bsdiff " |
| 337 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); | 337 << (base::Time::Now() - start_bsdiff_time).InSecondsF(); |
| 338 | 338 |
| 339 return OK; | 339 return OK; |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace courgette | 342 } // namespace courgette |
| OLD | NEW |