1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

AK: Define a traits helper for case-insensitive StringView hashing

Currently, we define a CaseInsensitiveStringTraits structure for String.
Using this structure for StringView involves allocating a String from
that view, and a second string to convert that intermediate string to
lowercase.

This defines CaseInsensitiveStringViewTraits (and the underlying helper
case_insensitive_string_hash) to avoid allocations.
This commit is contained in:
Timothy Flynn 2022-01-10 11:47:23 -05:00 committed by Linus Groh
parent 7d9b6b41c3
commit 3dccaa39d8
3 changed files with 43 additions and 0 deletions

View file

@ -189,3 +189,15 @@ TEST_CASE(constexpr_stuff)
}
#undef do_test
}
TEST_CASE(case_insensitive_hash)
{
auto string1 = "abcdef"sv;
auto string2 = "ABCDEF"sv;
auto string3 = "aBcDeF"sv;
auto string4 = "foo"sv;
EXPECT_EQ(CaseInsensitiveStringViewTraits::hash(string1), CaseInsensitiveStringViewTraits::hash(string2));
EXPECT_EQ(CaseInsensitiveStringViewTraits::hash(string1), CaseInsensitiveStringViewTraits::hash(string3));
EXPECT_NE(CaseInsensitiveStringViewTraits::hash(string1), CaseInsensitiveStringViewTraits::hash(string4));
}