AK: Mark MemMem header-only functions as inline rather than static

Avoid including a per-translation unit copy of all these functions.

Also, drive-by two clang-tidy fixes for readability-qualified-auto and
readability-implicit-bool-conversion.
This commit is contained in:
Andrew Kaster 2021-11-20 14:09:22 -07:00 committed by Ali Mohammad Pur
parent 0982a73d1d
commit bf33a14081

View file

@ -14,8 +14,8 @@
namespace AK { namespace AK {
namespace { namespace Detail {
const static void* bitap_bitwise(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length) inline constexpr const void* bitap_bitwise(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length)
{ {
VERIFY(needle_length < 32); VERIFY(needle_length < 32);
@ -34,7 +34,7 @@ const static void* bitap_bitwise(const void* haystack, size_t haystack_length, c
lookup |= needle_mask[((const u8*)haystack)[i]]; lookup |= needle_mask[((const u8*)haystack)[i]];
lookup <<= 1; lookup <<= 1;
if (!(lookup & (0x00000001 << needle_length))) if (0 == (lookup & (0x00000001 << needle_length)))
return ((const u8*)haystack) + i - needle_length + 1; return ((const u8*)haystack) + i - needle_length + 1;
} }
@ -43,7 +43,7 @@ const static void* bitap_bitwise(const void* haystack, size_t haystack_length, c
} }
template<typename HaystackIterT> template<typename HaystackIterT>
static inline Optional<size_t> memmem(const HaystackIterT& haystack_begin, const HaystackIterT& haystack_end, Span<const u8> needle) requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); }) inline Optional<size_t> memmem(const HaystackIterT& haystack_begin, const HaystackIterT& haystack_end, Span<const u8> needle) requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); })
{ {
auto prepare_kmp_partial_table = [&] { auto prepare_kmp_partial_table = [&] {
Vector<int, 64> table; Vector<int, 64> table;
@ -100,7 +100,7 @@ static inline Optional<size_t> memmem(const HaystackIterT& haystack_begin, const
return {}; return {};
} }
static inline Optional<size_t> memmem_optional(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length) inline Optional<size_t> memmem_optional(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length)
{ {
if (needle_length == 0) if (needle_length == 0)
return 0; return 0;
@ -115,7 +115,7 @@ static inline Optional<size_t> memmem_optional(const void* haystack, size_t hays
} }
if (needle_length < 32) { if (needle_length < 32) {
auto ptr = bitap_bitwise(haystack, haystack_length, needle, needle_length); auto const* ptr = Detail::bitap_bitwise(haystack, haystack_length, needle, needle_length);
if (ptr) if (ptr)
return static_cast<size_t>((FlatPtr)ptr - (FlatPtr)haystack); return static_cast<size_t>((FlatPtr)ptr - (FlatPtr)haystack);
return {}; return {};
@ -126,7 +126,7 @@ static inline Optional<size_t> memmem_optional(const void* haystack, size_t hays
return memmem(spans.begin(), spans.end(), { (const u8*)needle, needle_length }); return memmem(spans.begin(), spans.end(), { (const u8*)needle, needle_length });
} }
static inline const void* memmem(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length) inline const void* memmem(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length)
{ {
auto offset = memmem_optional(haystack, haystack_length, needle, needle_length); auto offset = memmem_optional(haystack, haystack_length, needle, needle_length);
if (offset.has_value()) if (offset.has_value())