| 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 29 matching lines...) Expand all Loading... |
| 40 // Copyright 2016 The Chromium Authors. All rights reserved. | 40 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 41 // Use of this source code is governed by a BSD-style license that can be | 41 // Use of this source code is governed by a BSD-style license that can be |
| 42 // found in the LICENSE file. | 42 // found in the LICENSE file. |
| 43 | 43 |
| 44 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ | 44 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ |
| 45 #define COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ | 45 #define COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ |
| 46 | 46 |
| 47 #include <algorithm> | 47 #include <algorithm> |
| 48 #include <cstring> | 48 #include <cstring> |
| 49 | 49 |
| 50 namespace courgette { | 50 namespace bsdiff { |
| 51 | 51 |
| 52 // Similar to ::memcmp(), but returns match length instead. | 52 // Similar to ::memcmp(), but returns match length instead. |
| 53 inline int matchlen(const unsigned char* old, | 53 inline int matchlen(const unsigned char* old, |
| 54 int oldsize, | 54 int oldsize, |
| 55 const unsigned char* newbuf, | 55 const unsigned char* newbuf, |
| 56 int newsize) { | 56 int newsize) { |
| 57 int i; | 57 int i; |
| 58 | 58 |
| 59 for (i = 0; (i < oldsize) && (i < newsize); i++) | 59 for (i = 0; (i < oldsize) && (i < newsize); i++) |
| 60 if (old[i] != newbuf[i]) | 60 if (old[i] != newbuf[i]) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 89 int x = matchlen(old + I[lo], oldsize - I[lo], newbuf, newsize); | 89 int x = matchlen(old + I[lo], oldsize - I[lo], newbuf, newsize); |
| 90 int y = matchlen(old + I[hi], oldsize - I[hi], newbuf, newsize); | 90 int y = matchlen(old + I[hi], oldsize - I[hi], newbuf, newsize); |
| 91 if (x > y) { | 91 if (x > y) { |
| 92 *pos = I[lo]; | 92 *pos = I[lo]; |
| 93 return x; | 93 return x; |
| 94 } | 94 } |
| 95 *pos = I[hi]; | 95 *pos = I[hi]; |
| 96 return y; | 96 return y; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace courgette | 99 } // namespace bsdiff |
| 100 | 100 |
| 101 #endif // COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ | 101 #endif // COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_SEARCH_H_ |
| OLD | NEW |