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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/BUILD.gn ('k') | url/scheme_set.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/scheme_set.h
diff --git a/url/scheme_set.h b/url/scheme_set.h
new file mode 100644
index 0000000000000000000000000000000000000000..f74ab7f3415e6cea2ac7a118df512e3dfc754e85
--- /dev/null
+++ b/url/scheme_set.h
@@ -0,0 +1,59 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef URL_SCHEME_SET_H_
+#define URL_SCHEME_SET_H_
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "base/strings/string_util.h"
+
+namespace url {
+
+// Data structure for fast |contains| operations. Schemes are kepts in a
+// contiguous block of memory.
+// TODO(csharrison): Add a remove method, and use this in the SchemeRegistry in
+// Blink.
+class SchemeSet {
+ public:
+ static const size_t npos = static_cast<size_t>(-1);
+ SchemeSet();
+ ~SchemeSet();
+
+ void add(const char* scheme);
+
+ // TODO(csharrison): Implement a fast path for schemes guaranteed to be
+ // canonicalized, so equality checking can be done in a case sensitive manner.
+ template <typename STR>
+ size_t find(const base::BasicStringPiece<STR>& scheme) {
+ if (scheme.empty())
+ return false; // Empty or invalid schemes are non-standard.
+ for (size_t i = 0; i < pieces_.size(); ++i) {
+ const auto& scheme_piece = pieces_[i];
+ base::StringPiece piece = base::StringPiece(
+ backing_string_.c_str() + scheme_piece.begin, scheme_piece.end);
+ if (base::LowerCaseEqualsASCII(scheme, piece))
+ return i;
+ }
+ return npos;
+ }
+
+ private:
+ struct SchemeIndex {
+ SchemeIndex(size_t begin, size_t end) : begin(begin), end(end) {}
+ size_t begin;
+ size_t end;
+ };
+ std::vector<SchemeIndex> pieces_;
+ std::string backing_string_;
+
+ DISALLOW_COPY_AND_ASSIGN(SchemeSet);
+};
+
+} // namespace url
+
+#endif // URL_SCHEME_SET_H_
« 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