Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: courgette/third_party/bsdiff/qsufsort.h

Issue 2078743002: [Courgette] Make BSDiff search() use lexicographical_compare(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
41 // http://www.larsson.dogma.net/qsufsort.c 41 // http://www.larsson.dogma.net/qsufsort.c
42 // --Samuel Huang <huangs@chromium.org> 42 // --Samuel Huang <huangs@chromium.org>
43 43
44 // Copyright 2016 The Chromium Authors. All rights reserved. 44 // Copyright 2016 The Chromium Authors. All rights reserved.
45 // Use of this source code is governed by a BSD-style license that can be 45 // Use of this source code is governed by a BSD-style license that can be
46 // found in the LICENSE file. 46 // found in the LICENSE file.
47 47
48 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_ 48 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_
49 #define COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_ 49 #define COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_
50 50
51 #include <algorithm>
52 #include <cstring>
53
54 namespace courgette { 51 namespace courgette {
55 namespace qsuf { 52 namespace qsuf {
56 53
57 // ------------------------------------------------------------------------ 54 // ------------------------------------------------------------------------
58 // 55 //
59 // The following code is taken verbatim from 'bsdiff.c'. Please keep all the 56 // The following code is taken verbatim from 'bsdiff.c'. Please keep all the
60 // code formatting and variable names. The changes from the original are: 57 // code formatting and variable names. The changes from the original are:
61 // (1) replacing tabs with spaces, 58 // (1) replacing tabs with spaces,
62 // (2) indentation and spacing, 59 // (2) indentation and spacing,
63 // (3) using 'const', 60 // (3) using 'const',
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 }; 210 };
214 }; 211 };
215 if (len) 212 if (len)
216 I[i - len] = -len; 213 I[i - len] = -len;
217 }; 214 };
218 215
219 for (i = 0; i < oldsize + 1; i++) 216 for (i = 0; i < oldsize + 1; i++)
220 I[V[i]] = i; 217 I[V[i]] = i;
221 } 218 }
222 219
223 static int matchlen(const unsigned char* old,
224 int oldsize,
225 const unsigned char* newbuf,
226 int newsize) {
227 int i;
228
229 for (i = 0; (i < oldsize) && (i < newsize); i++)
230 if (old[i] != newbuf[i])
231 break;
232
233 return i;
234 }
235
236 template <class T>
237 static int search(T I,
238 const unsigned char* old,
239 int oldsize,
240 const unsigned char* newbuf,
241 int newsize,
242 int* pos) {
243 int lo = 0;
244 int hi = oldsize;
245 while (hi - lo >= 2) {
246 int mid = (lo + hi) / 2;
247 if (memcmp(old + I[mid], newbuf, std::min(oldsize - I[mid], newsize)) < 0) {
248 lo = mid;
249 } else {
250 hi = mid;
251 }
252 }
253
254 int x = matchlen(old + I[lo], oldsize - I[lo], newbuf, newsize);
255 int y = matchlen(old + I[hi], oldsize - I[hi], newbuf, newsize);
256 if (x > y) {
257 *pos = I[lo];
258 return x;
259 }
260 *pos = I[hi];
261 return y;
262 }
263
264 // End of 'verbatim' code. 220 // End of 'verbatim' code.
265 // ------------------------------------------------------------------------ 221 // ------------------------------------------------------------------------
266 222
267 } // namespace qsuf 223 } // namespace qsuf
268 } // namespace courgette 224 } // namespace courgette
225
269 #endif // COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_ 226 #endif // COURGETTE_THIRD_PARTY_BSDIFF_QSUFSORT_H_
OLDNEW
« no previous file with comments | « courgette/third_party/bsdiff/bsdiff_search_unittest.cc ('k') | courgette/third_party/bsdiff/qsufsort_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698