Skip to content

Commit 7a19975

Browse files
author
Kyu Hyun Chang
committed
Replace std::set with std::unordered_set in path matcher
1 parent 8720eba commit 7a19975

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/include/grpc_transcoding/path_matcher.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
#include <cstddef>
1919
#include <memory>
20-
#include <set>
2120
#include <sstream>
2221
#include <string>
2322
#include <unordered_map>
23+
#include <unordered_set>
2424

2525
#include "http_template.h"
2626
#include "path_matcher_node.h"
@@ -71,13 +71,13 @@ class PathMatcher {
7171
// registered to this node.
7272
std::unique_ptr<PathMatcherNode> root_ptr_;
7373
// Holds the set of custom verbs found in configured templates.
74-
std::set<std::string> custom_verbs_;
74+
std::unordered_set<std::string> custom_verbs_;
7575
// Data we store per each registered method
7676
struct MethodData {
7777
Method method;
7878
std::vector<HttpTemplate::Variable> variables;
7979
std::string body_field_path;
80-
std::set<std::string> system_query_parameter_names;
80+
std::unordered_set<std::string> system_query_parameter_names;
8181
};
8282
// The info associated with each method. The path matcher nodes
8383
// will hold pointers to MethodData objects in this vector.
@@ -105,10 +105,11 @@ class PathMatcherBuilder {
105105
// Registrations are one-to-one. If this function is called more than once, it
106106
// replaces the existing method. Only the last registered method is stored.
107107
// Return false if path is an invalid http template.
108-
bool Register(const std::string& http_method, const std::string& path,
109-
const std::string& body_field_path,
110-
const std::set<std::string>& system_query_parameter_names,
111-
Method method);
108+
bool Register(
109+
const std::string& http_method, const std::string& path,
110+
const std::string& body_field_path,
111+
const std::unordered_set<std::string>& system_query_parameter_names,
112+
Method method);
112113
bool Register(const std::string& http_method, const std::string& path,
113114
const std::string& body_field_path, Method method);
114115

@@ -129,7 +130,7 @@ class PathMatcherBuilder {
129130
// TODO: Perhaps this should not be at this level because there will
130131
// be multiple templates in different services on a server. Consider moving
131132
// this to PathMatcherNode.
132-
std::set<std::string> custom_verbs_;
133+
std::unordered_set<std::string> custom_verbs_;
133134
typedef typename PathMatcher<Method>::MethodData MethodData;
134135
std::vector<std::unique_ptr<MethodData>> methods_;
135136

@@ -291,7 +292,8 @@ void ExtractBindingsFromPath(const std::vector<HttpTemplate::Variable>& vars,
291292

292293
template <class VariableBinding>
293294
void ExtractBindingsFromQueryParameters(
294-
const std::string& query_params, const std::set<std::string>& system_params,
295+
const std::string& query_params,
296+
const std::unordered_set<std::string>& system_params,
295297
std::vector<VariableBinding>* bindings) {
296298
// The bindings in URL the query parameters have the following form:
297299
// <field_path1>=value1&<field_path2>=value2&...&<field_pathN>=valueN
@@ -476,7 +478,8 @@ template <class Method>
476478
bool PathMatcherBuilder<Method>::Register(
477479
const std::string& http_method, const std::string& http_template,
478480
const std::string& body_field_path,
479-
const std::set<std::string>& system_query_parameter_names, Method method) {
481+
const std::unordered_set<std::string>& system_query_parameter_names,
482+
Method method) {
480483
std::unique_ptr<HttpTemplate> ht(HttpTemplate::Parse(http_template));
481484
if (nullptr == ht) {
482485
return false;

test/path_matcher_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class PathMatcherTest : public ::testing::Test {
9999

100100
MethodInfo* AddPathWithSystemParams(
101101
std::string http_method, std::string http_template,
102-
const std::set<std::string>* system_params) {
102+
const std::unordered_set<std::string>* system_params) {
103103
auto method = new MethodInfo();
104104
if (!builder_.Register(http_method, http_template, std::string(),
105105
*system_params, method)) {
@@ -150,7 +150,7 @@ class PathMatcherTest : public ::testing::Test {
150150
PathMatcherBuilder<MethodInfo*> builder_;
151151
PathMatcherPtr<MethodInfo*> matcher_;
152152
std::vector<std::unique_ptr<MethodInfo>> stored_methods_;
153-
std::set<std::string> empty_set_;
153+
std::unordered_set<std::string> empty_set_;
154154
};
155155

156156
TEST_F(PathMatcherTest, WildCardMatchesRoot) {
@@ -712,7 +712,7 @@ TEST_F(PathMatcherTest, VariableBindingsWithQueryParamsEncoding) {
712712
}
713713

714714
TEST_F(PathMatcherTest, VariableBindingsWithQueryParamsAndSystemParams) {
715-
std::set<std::string> system_params{"key", "api_key"};
715+
std::unordered_set<std::string> system_params{"key", "api_key"};
716716
MethodInfo* a_b = AddPathWithSystemParams("GET", "/a/{x}/b", &system_params);
717717
Build();
718718

0 commit comments

Comments
 (0)