Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: net/base/lookup_string_in_fixed_set_unittest.cc

Issue 2649033004: [3 of 4] Speedup GetRegistryLengthImpl() by seeding the DAFSA in reverse
Patch Set: Language. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/lookup_string_in_fixed_set.h" 5 #include "net/base/lookup_string_in_fixed_set.h"
6 6
7 #include <string.h>
8
9 #include <algorithm> 7 #include <algorithm>
10 #include <limits> 8 #include <limits>
11 #include <ostream> 9 #include <ostream>
12 #include <utility> 10 #include <utility>
13 #include <vector> 11 #include <vector>
14 12
15 #include "base/base_paths.h" 13 #include "base/base_paths.h"
16 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
18 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/string_piece.h"
19 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 namespace net { 22 namespace net {
24 namespace { 23 namespace {
25 namespace test1 { 24 namespace test1 {
26 #include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc .cc" 25 #include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc .cc"
27 } 26 }
28 namespace test3 { 27 namespace test3 {
(...skipping 14 matching lines...) Expand all
43 int value; 42 int value;
44 }; 43 };
45 44
46 void PrintTo(const Expectation& expectation, std::ostream* os) { 45 void PrintTo(const Expectation& expectation, std::ostream* os) {
47 *os << "{\"" << expectation.key << "\", " << expectation.value << "}"; 46 *os << "{\"" << expectation.key << "\", " << expectation.value << "}";
48 } 47 }
49 48
50 class LookupStringInFixedSetTest : public testing::TestWithParam<Expectation> { 49 class LookupStringInFixedSetTest : public testing::TestWithParam<Expectation> {
51 protected: 50 protected:
52 template <size_t N> 51 template <size_t N>
53 int LookupInGraph(const unsigned char(&graph)[N], const char* key) { 52 int LookupInGraph(const unsigned char (&graph)[N], base::StringPiece key) {
54 return LookupStringInFixedSet(graph, N, key, strlen(key)); 53 std::string rev_key(key.rbegin(), key.rend());
Ryan Sleevi 2017/03/06 17:20:04 Is it worth documenting why this is reversed?
54 return LookupStringInFixedSet(graph, N, rev_key.data(), rev_key.length());
55 } 55 }
56 }; 56 };
57 57
58 class Dafsa1Test : public LookupStringInFixedSetTest {}; 58 class Dafsa1Test : public LookupStringInFixedSetTest {};
59 59
60 TEST_P(Dafsa1Test, BasicTest) { 60 TEST_P(Dafsa1Test, BasicTest) {
61 const Expectation& param = GetParam(); 61 const Expectation& param = GetParam();
62 EXPECT_EQ(param.value, LookupInGraph(test1::kDafsa, param.key)); 62 EXPECT_EQ(param.value, LookupInGraph(test1::kDafsa, param.key));
63 } 63 }
64 64
65 const Expectation kBasicTestCases[] = { 65 const Expectation kBasicTestCases[] = {
66 {"", -1}, {"j", -1}, {"jp", 0}, {"jjp", -1}, {"jpp", -1}, 66 {"", -1}, {"j", -1}, {"jp", 0}, {"jjp", -1}, {"jpp", -1},
67 {"bar.jp", 2}, {"pref.bar.jp", 1}, {"c", 2}, {"b.c", 1}, {"priv.no", 4}, 67 {"bar.jp", 2}, {"pref.bar.jp", 1}, {"c", 2}, {"b.c", 1}, {"priv.no", 4},
68 }; 68 };
69 69
70 // Helper function for EnumerateDafsaLanaguage. 70 // Helper function for EnumerateDafsaLanaguage.
71 void RecursivelyEnumerateDafsaLanguage(const FixedSetIncrementalLookup& lookup, 71 void RecursivelyEnumerateDafsaLanguage(const FixedSetIncrementalLookup& lookup,
72 std::vector<char>* sequence, 72 std::vector<char>* sequence,
73 std::vector<std::string>* language) { 73 std::vector<std::string>* language) {
74 int result = lookup.GetResultForCurrentSequence(); 74 int result = lookup.GetResultForCurrentSequence();
75 if (result != kDafsaNotFound) { 75 if (result != kDafsaNotFound) {
76 std::string line(sequence->begin(), sequence->end()); 76 std::string line(sequence->rbegin(), sequence->rend());
Ryan Sleevi 2017/03/06 17:20:04 Similarly
77 line += base::StringPrintf(", %d", result); 77 line += base::StringPrintf(", %d", result);
78 language->emplace_back(std::move(line)); 78 language->emplace_back(std::move(line));
79 } 79 }
80 // Try appending each char value. 80 // Try appending each char value.
81 for (char c = std::numeric_limits<char>::min();; ++c) { 81 for (char c = std::numeric_limits<char>::min();; ++c) {
82 FixedSetIncrementalLookup continued_lookup = lookup; 82 FixedSetIncrementalLookup continued_lookup = lookup;
83 if (continued_lookup.Advance(c)) { 83 if (continued_lookup.Advance(c)) {
84 sequence->push_back(c); 84 sequence->push_back(c);
85 size_t saved_language_size = language->size(); 85 size_t saved_language_size = language->size();
86 RecursivelyEnumerateDafsaLanguage(continued_lookup, sequence, language); 86 RecursivelyEnumerateDafsaLanguage(continued_lookup, sequence, language);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 std::vector<std::string> expected_language = { 243 std::vector<std::string> expected_language = {
244 "ia, 0", "jb, 4", "kaa, 0", "lbb, 4", "maaaa, 0", "nbbbb, 0", 244 "ia, 0", "jb, 4", "kaa, 0", "lbb, 4", "maaaa, 0", "nbbbb, 0",
245 }; 245 };
246 246
247 EXPECT_EQ(expected_language, language); 247 EXPECT_EQ(expected_language, language);
248 } 248 }
249 249
250 } // namespace 250 } // namespace
251 } // namespace net 251 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698