@@ -38,8 +38,6 @@ class PublicSuffixData {
3838 bool is_public_suffix(StringView host);
3939 Optional<String> get_public_suffix(StringView string);
4040
41- private:
42- Trie<char, Empty> m_dictionary;
4341};
4442
4543}
@@ -52,13 +50,15 @@ class PublicSuffixData {
5250
5351def generate_implementation_file (input_path : Path , output_path : Path ) -> None :
5452 content = """#include <AK/String.h>
53+ #include <AK/BinarySearch.h>
5554#include <AK/Vector.h>
5655#include <LibURL/PublicSuffixData.h>
5756
5857namespace URL {
5958
6059static constexpr auto s_public_suffixes = Array {"""
6160
61+ reversed_lines = []
6262 with open (input_path , "r" , encoding = "utf-8" ) as f :
6363 for line in f :
6464 line = line .strip ()
@@ -67,25 +67,23 @@ def generate_implementation_file(input_path: Path, output_path: Path) -> None:
6767 continue
6868
6969 reversed_line = "." .join (line .split ("." )[::- 1 ])
70- content += f'\n "{ reversed_line } "sv,'
70+ reversed_lines .append (reversed_line )
71+
72+ reversed_lines .sort ()
73+
74+ for item in reversed_lines :
75+ content += f'\n "{ item } "sv,'
7176
7277 content += """
7378};
7479
75- PublicSuffixData::PublicSuffixData()
76- : m_dictionary('/')
77- {
78- // FIXME: Reduce the depth of this trie
79- for (auto str : s_public_suffixes) {
80- MUST(m_dictionary.insert(str.begin(), str.end(), Empty {}, [](auto const&, auto const&) -> Optional<Empty> { return {}; }));
81- }
80+ PublicSuffixData::PublicSuffixData()
81+ {
8282}
8383
8484bool PublicSuffixData::is_public_suffix(StringView host)
8585{
86- auto it = host.begin();
87- auto& node = m_dictionary.traverse_until_last_accessible_node(it, host.end());
88- return it.is_end() && node.has_metadata();
86+ return binary_search(s_public_suffixes, host);
8987}
9088
9189Optional<String> PublicSuffixData::get_public_suffix(StringView string)
0 commit comments