+++ /dev/null
-/* Copyright 2010 Google Inc. All Rights Reserved.\r
-\r
- Distributed under MIT license.\r
- See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
-*/\r
-\r
-/* Function to find maximal matching prefixes of strings. */\r
-\r
-#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_\r
-#define BROTLI_ENC_FIND_MATCH_LENGTH_H_\r
-\r
-#include "../common/platform.h"\r
-#include <brotli/types.h>\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-extern "C" {\r
-#endif\r
-\r
-/* Separate implementation for little-endian 64-bit targets, for speed. */\r
-#if defined(__GNUC__) && defined(_LP64) && defined(BROTLI_LITTLE_ENDIAN)\r
-\r
-static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,\r
- const uint8_t* s2,\r
- size_t limit) {\r
- size_t matched = 0;\r
- size_t limit2 = (limit >> 3) + 1; /* + 1 is for pre-decrement in while */\r
- while (BROTLI_PREDICT_TRUE(--limit2)) {\r
- if (BROTLI_PREDICT_FALSE(BROTLI_UNALIGNED_LOAD64LE(s2) ==\r
- BROTLI_UNALIGNED_LOAD64LE(s1 + matched))) {\r
- s2 += 8;\r
- matched += 8;\r
- } else {\r
- uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^\r
- BROTLI_UNALIGNED_LOAD64LE(s1 + matched);\r
- size_t matching_bits = (size_t)__builtin_ctzll(x);\r
- matched += matching_bits >> 3;\r
- return matched;\r
- }\r
- }\r
- limit = (limit & 7) + 1; /* + 1 is for pre-decrement in while */\r
- while (--limit) {\r
- if (BROTLI_PREDICT_TRUE(s1[matched] == *s2)) {\r
- ++s2;\r
- ++matched;\r
- } else {\r
- return matched;\r
- }\r
- }\r
- return matched;\r
-}\r
-#else\r
-static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,\r
- const uint8_t* s2,\r
- size_t limit) {\r
- size_t matched = 0;\r
- const uint8_t* s2_limit = s2 + limit;\r
- const uint8_t* s2_ptr = s2;\r
- /* Find out how long the match is. We loop over the data 32 bits at a\r
- time until we find a 32-bit block that doesn't match; then we find\r
- the first non-matching bit and use that to calculate the total\r
- length of the match. */\r
- while (s2_ptr <= s2_limit - 4 &&\r
- BrotliUnalignedRead32(s2_ptr) ==\r
- BrotliUnalignedRead32(s1 + matched)) {\r
- s2_ptr += 4;\r
- matched += 4;\r
- }\r
- while ((s2_ptr < s2_limit) && (s1[matched] == *s2_ptr)) {\r
- ++s2_ptr;\r
- ++matched;\r
- }\r
- return matched;\r
-}\r
-#endif\r
-\r
-#if defined(__cplusplus) || defined(c_plusplus)\r
-} /* extern "C" */\r
-#endif\r
-\r
-#endif /* BROTLI_ENC_FIND_MATCH_LENGTH_H_ */\r