Skip to content

Commit

Permalink
[http_server] Manage srings by unordered_set<string> efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
cong1920 committed Dec 30, 2024
1 parent b00957b commit 667ac8f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libraries/http_server/http_server/dynamic_routing_table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>

namespace li {

Expand Down Expand Up @@ -114,14 +115,14 @@ template <typename V> struct dynamic_routing_table {

// Find a route and return reference to a procedure.
auto& operator[](const std::string_view& r) {
strings.push_back(std::make_shared<std::string>(r));
std::string_view r2(*strings.back());
auto [itr, is_inserted] = strings.emplace(std::string(r));
std::string_view r2(*itr);
return root.find_or_create(r2, 0);
}
auto& operator[](const std::string& r) {
strings.push_back(std::make_shared<std::string>(r));
std::string_view r2(*strings.back());
return root.find_or_create(r2, 0);
auto& operator[](const std::string& s) {
auto [itr, is_inserted] = strings.emplace(s);
std::string_view r(*itr);
return root.find_or_create(r, 0);
}

// Find a route and return an iterator.
Expand All @@ -130,7 +131,7 @@ template <typename V> struct dynamic_routing_table {
template <typename F> void for_all_routes(F f) const { root.for_all_routes(f); }
auto end() const { return root.end(); }

std::vector<std::shared_ptr<std::string>> strings;
std::unordered_set<std::string> strings;
internal::drt_node<V> root;
};

Expand Down

0 comments on commit 667ac8f

Please sign in to comment.