summaryrefslogtreecommitdiff
path: root/http/routing.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-22 22:13:24 +0300
committerEd Tanous <ed@tanous.net>2022-03-01 00:08:49 +0300
commita94ac61f69fd3768cf609adc75cfd646c558eb7e (patch)
treee8d78d0e7eae46cb40de1ddb653d8c37c6b6818f /http/routing.hpp
parentc5a4c82ad109fc7d6ca7af3ca3dfe4481c9b2346 (diff)
downloadbmcweb-a94ac61f69fd3768cf609adc75cfd646c558eb7e.tar.xz
Make the router const correct
Subtly, the individual members of a const std::pair are not implicitly const. In most cases, this is solved by a compiler error, but it seems that flat_map allows implicitly pulling out by a non const reference, even when the underlying container is const. This is not how the maps should work. This commit changes the router to declare a "ChildMap" type, which can then use the value_type to make this const correctness stuff more reasonable to manage. Tested: Code compiles. No-op const change. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id99079a86e392a03416a69506934dbfff7bc3b29
Diffstat (limited to 'http/routing.hpp')
-rw-r--r--http/routing.hpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/http/routing.hpp b/http/routing.hpp
index b39442bd3a..250cd3354e 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -671,7 +671,10 @@ class Trie
unsigned ruleIndex{};
std::array<size_t, static_cast<size_t>(ParamType::MAX)>
paramChildrens{};
- boost::container::flat_map<std::string, unsigned> children;
+ using ChildMap = boost::container::flat_map<
+ std::string, unsigned, std::less<>,
+ std::vector<std::pair<std::string, unsigned>>>;
+ ChildMap children;
bool isSimpleNode() const
{
@@ -702,7 +705,7 @@ class Trie
return;
}
bool mergeWithChild = true;
- for (const std::pair<std::string, unsigned>& kv : node->children)
+ for (const Node::ChildMap::value_type& kv : node->children)
{
Node* child = &nodes[kv.second];
if (!child->isSimpleNode())
@@ -713,11 +716,11 @@ class Trie
}
if (mergeWithChild)
{
- decltype(node->children) merged;
- for (const std::pair<std::string, unsigned>& kv : node->children)
+ Node::ChildMap merged;
+ for (const Node::ChildMap::value_type& kv : node->children)
{
Node* child = &nodes[kv.second];
- for (const std::pair<std::string, unsigned>& childKv :
+ for (const Node::ChildMap::value_type& childKv :
child->children)
{
merged[kv.first + childKv.first] = childKv.second;
@@ -728,7 +731,7 @@ class Trie
}
else
{
- for (const std::pair<std::string, unsigned>& kv : node->children)
+ for (const Node::ChildMap::value_type& kv : node->children)
{
Node* child = &nodes[kv.second];
optimizeNode(child);
@@ -755,7 +758,7 @@ class Trie
{
node = head();
}
- for (const std::pair<std::string, unsigned>& kv : node->children)
+ for (const Node::ChildMap::value_type& kv : node->children)
{
const std::string& fragment = kv.first;
const Node* child = &nodes[kv.second];
@@ -922,7 +925,7 @@ class Trie
}
}
- for (const std::pair<std::string, unsigned>& kv : node->children)
+ for (const Node::ChildMap::value_type& kv : node->children)
{
const std::string& fragment = kv.first;
const Node* child = &nodes[kv.second];
@@ -1028,7 +1031,7 @@ class Trie
debugNodePrint(&nodes[n->paramChildrens[i]], level + 1);
}
}
- for (const std::pair<std::string, unsigned>& kv : n->children)
+ for (const Node::ChildMap::value_type& kv : n->children)
{
BMCWEB_LOG_DEBUG
<< std::string(2U * level, ' ') /*<< "(" << kv.second << ") "*/