Skip to content

Commit

Permalink
Optimize _node_route_map's usage in WebNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Relintai committed May 4, 2024
1 parent 942e7e8 commit 8953d84
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/web/http/web_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ bool WebNode::try_route_request_to_children(Ref<WebServerRequest> request) {
} else {
String main_route = request->get_current_path_segment();

handler = _node_route_map[main_route];
WebNode **v = _node_route_map.getptr(main_route);

if (v) {
handler = *v;
}
}

_handler_map_lock.read_unlock();
Expand Down Expand Up @@ -369,7 +373,12 @@ WebNode *WebNode::get_request_handler_child(Ref<WebServerRequest> request) {
handler = _index_node;
} else {
const String &main_route = request->get_current_path_segment();
handler = _node_route_map[main_route];

WebNode **v = _node_route_map.getptr(main_route);

if (v) {
handler = *v;
}
}

_handler_map_lock.read_unlock();
Expand Down Expand Up @@ -400,7 +409,7 @@ void WebNode::build_handler_map() {

_index_node = c;
} else {
ERR_CONTINUE_MSG(_node_route_map[uri_segment], "You have multiple of the same uri! URI: " + uri_segment);
ERR_CONTINUE_MSG(_node_route_map.has(uri_segment), "You have multiple of the same uri! URI: " + uri_segment);

_node_route_map[uri_segment] = c;
}
Expand Down

0 comments on commit 8953d84

Please sign in to comment.