From 5141c865879bc8de6ffd98d4ea6f3fbd59b6434b Mon Sep 17 00:00:00 2001 From: gustrb Date: Tue, 14 Mar 2023 08:40:53 -0300 Subject: [PATCH] AK: Rename CaseInsensitiveStringViewTraits to reflect intent Now it is called `CaseInsensitiveASCIIStringViewTraits`, so we can be more specific about what data structure does it operate onto. ;) --- AK/StringView.h | 5 ++--- .../CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp | 2 +- .../Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp | 2 +- Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h | 2 +- .../Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp | 2 +- Tests/AK/TestHashMap.cpp | 2 +- Tests/AK/TestStringView.cpp | 6 +++--- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/AK/StringView.h b/AK/StringView.h index aeccf623c4a..c2ea6759dda 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -359,8 +359,7 @@ struct Traits : public GenericTraits { static unsigned hash(StringView s) { return s.hash(); } }; -// FIXME: Rename this to indicate that it's about ASCII-only case insensitivity. -struct CaseInsensitiveStringViewTraits : public Traits { +struct CaseInsensitiveASCIIStringViewTraits : public Traits { static unsigned hash(StringView s) { if (s.is_empty()) @@ -386,6 +385,6 @@ struct CaseInsensitiveStringViewTraits : public Traits { } #if USING_AK_GLOBALLY -using AK::CaseInsensitiveStringViewTraits; +using AK::CaseInsensitiveASCIIStringViewTraits; using AK::StringView; #endif diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp index a9f7d604674..b93aa98174b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp @@ -613,7 +613,7 @@ static constexpr Array s_time_zone_locations { { TRY(hashes.try_ensure_capacity(values.size())); auto hash = [](auto const& value) { - return CaseInsensitiveStringViewTraits::hash(value); + return CaseInsensitiveASCIIStringViewTraits::hash(value); }; for (auto const& value : values) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp index a229ea82382..31c984dab6e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeData.cpp @@ -1316,7 +1316,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@) for (auto const& prop : prop_list) { if constexpr (IsSame, DeprecatedString>) { - hashes.set(CaseInsensitiveStringViewTraits::hash(prop), prop); + hashes.set(CaseInsensitiveASCIIStringViewTraits::hash(prop), prop); options.sensitivity = CaseSensitivity::CaseInsensitive; } else { hashes.set(prop.key.hash(), prop.key); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h index d10ca258d33..1031cec4dff 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h @@ -454,7 +454,7 @@ Optional<@return_type@> @method_name@(StringView key) )~~~"); } else { generator.append(R"~~~( - auto hash = CaseInsensitiveStringViewTraits::hash(key); + auto hash = CaseInsensitiveASCIIStringViewTraits::hash(key); )~~~"); } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp index 7d2642608ab..fbc53f7882d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSValueID.cpp @@ -90,7 +90,7 @@ ErrorOr generate_implementation_file(JsonArray& identifier_data, Core::Fil namespace Web::CSS { -HashMap g_stringview_to_value_id_map { +HashMap g_stringview_to_value_id_map { )~~~"); identifier_data.for_each([&](auto& name) { diff --git a/Tests/AK/TestHashMap.cpp b/Tests/AK/TestHashMap.cpp index 3ca4dbe71bb..b16534d625e 100644 --- a/Tests/AK/TestHashMap.cpp +++ b/Tests/AK/TestHashMap.cpp @@ -111,7 +111,7 @@ TEST_CASE(case_insensitive) TEST_CASE(case_insensitive_stringview) { - HashMap casemap; + HashMap casemap; EXPECT_EQ(casemap.set("nickserv"sv, 3), AK::HashSetResult::InsertedNewEntry); EXPECT_EQ(casemap.set("NickServ"sv, 3), AK::HashSetResult::ReplacedExistingEntry); EXPECT_EQ(casemap.size(), 1u); diff --git a/Tests/AK/TestStringView.cpp b/Tests/AK/TestStringView.cpp index 39b19f3a3eb..bc098bc1378 100644 --- a/Tests/AK/TestStringView.cpp +++ b/Tests/AK/TestStringView.cpp @@ -196,7 +196,7 @@ TEST_CASE(case_insensitive_hash) 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)); + EXPECT_EQ(CaseInsensitiveASCIIStringViewTraits::hash(string1), CaseInsensitiveASCIIStringViewTraits::hash(string2)); + EXPECT_EQ(CaseInsensitiveASCIIStringViewTraits::hash(string1), CaseInsensitiveASCIIStringViewTraits::hash(string3)); + EXPECT_NE(CaseInsensitiveASCIIStringViewTraits::hash(string1), CaseInsensitiveASCIIStringViewTraits::hash(string4)); }