diff --git a/AK/MemMem.h b/AK/MemMem.h index fb7821c6f6..25a2e455b0 100644 --- a/AK/MemMem.h +++ b/AK/MemMem.h @@ -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 -static inline Optional memmem(const HaystackIterT& haystack_begin, const HaystackIterT& haystack_end, Span needle) requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); }) +inline Optional memmem(const HaystackIterT& haystack_begin, const HaystackIterT& haystack_end, Span needle) requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); }) { auto prepare_kmp_partial_table = [&] { Vector table; @@ -100,7 +100,7 @@ static inline Optional memmem(const HaystackIterT& haystack_begin, const return {}; } -static inline Optional memmem_optional(const void* haystack, size_t haystack_length, const void* needle, size_t needle_length) +inline Optional 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 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((FlatPtr)ptr - (FlatPtr)haystack); return {}; @@ -126,7 +126,7 @@ static inline Optional 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())