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

Side by Side Diff: url/scheme_set.h

Issue 2492753002: [WIP] [url_utils] Implement a contiguous SchemeSet to replace vector<SchemeWithType>
Patch Set: separate SchemeSet for blink migration Created 4 years 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
« no previous file with comments | « url/BUILD.gn ('k') | url/scheme_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef URL_SCHEME_SET_H_
6 #define URL_SCHEME_SET_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/strings/string_piece.h"
13 #include "base/strings/string_util.h"
14
15 namespace url {
16
17 // Data structure for fast |contains| operations. Schemes are kepts in a
18 // contiguous block of memory.
19 // TODO(csharrison): Add a remove method, and use this in the SchemeRegistry in
20 // Blink.
21 class SchemeSet {
22 public:
23 static const size_t npos = static_cast<size_t>(-1);
24 SchemeSet();
25 ~SchemeSet();
26
27 void add(const char* scheme);
28
29 // TODO(csharrison): Implement a fast path for schemes guaranteed to be
30 // canonicalized, so equality checking can be done in a case sensitive manner.
31 template <typename STR>
32 size_t find(const base::BasicStringPiece<STR>& scheme) {
33 if (scheme.empty())
34 return false; // Empty or invalid schemes are non-standard.
35 for (size_t i = 0; i < pieces_.size(); ++i) {
36 const auto& scheme_piece = pieces_[i];
37 base::StringPiece piece = base::StringPiece(
38 backing_string_.c_str() + scheme_piece.begin, scheme_piece.end);
39 if (base::LowerCaseEqualsASCII(scheme, piece))
40 return i;
41 }
42 return npos;
43 }
44
45 private:
46 struct SchemeIndex {
47 SchemeIndex(size_t begin, size_t end) : begin(begin), end(end) {}
48 size_t begin;
49 size_t end;
50 };
51 std::vector<SchemeIndex> pieces_;
52 std::string backing_string_;
53
54 DISALLOW_COPY_AND_ASSIGN(SchemeSet);
55 };
56
57 } // namespace url
58
59 #endif // URL_SCHEME_SET_H_
OLDNEW
« no previous file with comments | « url/BUILD.gn ('k') | url/scheme_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698