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 {
const static void* bitap_bitwise(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length)
namespace Detail {
inline constexpr const void* bitap_bitwise(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length)
{
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 <<= 1;
if (!(lookup & (0x00000001 << needle_length)))
if (0 == (lookup & (0x00000001 << needle_length)))
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>
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 = [&] {
Vector<int, 64> table;
@ -100,7 +100,7 @@ static inline Optional<size_t> memmem(const HaystackIterT& haystack_begin, const
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)
return 0;
@ -115,7 +115,7 @@ static inline Optional<size_t> memmem_optional(const void* haystack, size_t hays
}
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)
return static_cast<size_t>((FlatPtr)ptr - (FlatPtr)haystack);
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 });
}
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);
if (offset.has_value())