Skip to content

Commit

Permalink
removed unnecessary code / added constexpr for max bp id
Browse files Browse the repository at this point in the history
  • Loading branch information
The-EDev committed Aug 3, 2021
1 parent 2d65f71 commit 2def62b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
6 changes: 0 additions & 6 deletions include/crow/app.h
Expand Up @@ -84,12 +84,6 @@ namespace crow
return router_.new_rule_dynamic(std::move(rule));
}

// ///Create a dynamic route for a blueprint using a rule (**Use CROW_BP_ROUTE instead**)
// DynamicRule& route_dynamic(Blueprint& blueprint, std::string&& rule)
// {
// return blueprint.new_rule_dynamic(std::move(rule));
// }

///Create a route using a rule (**Use CROW_ROUTE instead**)
template <uint64_t Tag>
auto route(std::string&& rule)
Expand Down
21 changes: 12 additions & 9 deletions include/crow/routing.h
Expand Up @@ -717,7 +717,7 @@ namespace crow
{
uint16_t rule_index{};
// Assign the index to the maximum 32 unsigned integer value by default so that any other number (specifically 0) is a valid BP id.
uint16_t blueprint_index{0xFFFF};
uint16_t blueprint_index{INVALID_BP_ID};
std::string key;
ParamType param = ParamType::MAX; // MAX = No param.
std::vector<Node*> children;
Expand All @@ -726,7 +726,7 @@ namespace crow
{
return
!rule_index &&
blueprint_index == 0xFFFF &&
blueprint_index == INVALID_BP_ID &&
children.size() < 2 &&
param == ParamType::MAX &&
std::all_of(std::begin(children), std::end(children), [](Node* x){ return x->param == ParamType::MAX; });
Expand Down Expand Up @@ -754,6 +754,8 @@ namespace crow


private:


void optimizeNode(Node* node)
{
if (node->children.empty())
Expand Down Expand Up @@ -830,7 +832,6 @@ namespace crow
//Rule_index, Blueprint_index, routing_params
std::tuple<uint16_t, std::vector<uint16_t>, routing_params> find(const std::string& req_url, const Node* node = nullptr, unsigned pos = 0, routing_params* params = nullptr, std::vector<uint16_t>* blueprints = nullptr) const
{
static const uint16_t idx_max{0xFFFF};
//start params as an empty struct
routing_params empty;
if (params == nullptr)
Expand Down Expand Up @@ -883,7 +884,7 @@ namespace crow
{
found_fragment = true;
params->int_params.push_back(value);
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
update_found(ret);
params->int_params.pop_back();
Expand All @@ -904,7 +905,7 @@ namespace crow
{
found_fragment = true;
params->uint_params.push_back(value);
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
update_found(ret);
params->uint_params.pop_back();
Expand All @@ -925,7 +926,7 @@ namespace crow
{
found_fragment = true;
params->double_params.push_back(value);
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, eptr - req_url.data(), params, blueprints);
update_found(ret);
params->double_params.pop_back();
Expand All @@ -947,7 +948,7 @@ namespace crow
{
found_fragment = true;
params->string_params.push_back(req_url.substr(pos, epos-pos));
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, epos, params, blueprints);
update_found(ret);
params->string_params.pop_back();
Expand All @@ -963,7 +964,7 @@ namespace crow
{
found_fragment = true;
params->string_params.push_back(req_url.substr(pos, epos-pos));
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, epos, params, blueprints);
update_found(ret);
params->string_params.pop_back();
Expand All @@ -978,7 +979,7 @@ namespace crow
if (req_url.compare(pos, fragment.size(), fragment) == 0)
{
found_fragment = true;
if (child->blueprint_index != idx_max) blueprints->push_back(child->blueprint_index);
if (child->blueprint_index != INVALID_BP_ID) blueprints->push_back(child->blueprint_index);
auto ret = find(req_url, child, pos + fragment.size(), params, blueprints);
update_found(ret);
blueprints->pop_back();
Expand Down Expand Up @@ -1105,6 +1106,8 @@ namespace crow
return children[children.size()-1];
}

static constexpr uint16_t INVALID_BP_ID{0xFFFF};

Node head_;
};

Expand Down

0 comments on commit 2def62b

Please sign in to comment.