From: Arnaud Giersch Date: Fri, 13 Oct 2017 08:08:11 +0000 (+0200) Subject: Remove an indirection and fix memory leak. X-Git-Tag: v3.18~478^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b6f037cf41a18ef8974469496e710093d8e1ab75 Remove an indirection and fix memory leak. --- diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index 3cb87afd6e..4c2d62c2bb 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -81,14 +81,12 @@ xbt_node_t DijkstraZone::routeGraphNewNode(int id, int graph_id) data->graph_id = graph_id; xbt_node_t node = xbt_graph_new_node(routeGraph_, data); - graph_node_map_element_t elm = new s_graph_node_map_element_t; - elm->node = node; - graphNodeMap_.insert({id, elm}); + graphNodeMap_.emplace(id, node); return node; } -graph_node_map_element_t DijkstraZone::nodeMapSearch(int id) +xbt_node_t DijkstraZone::nodeMapSearch(int id) { auto ret = graphNodeMap_.find(id); return ret == graphNodeMap_.end() ? nullptr : ret->second; @@ -102,14 +100,14 @@ void DijkstraZone::newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_rou xbt_node_t src = nullptr; xbt_node_t dst = nullptr; - graph_node_map_element_t src_elm = nodeMapSearch(src_id); - graph_node_map_element_t dst_elm = nodeMapSearch(dst_id); + xbt_node_t src_elm = nodeMapSearch(src_id); + xbt_node_t dst_elm = nodeMapSearch(dst_id); if (src_elm) - src = src_elm->node; + src = src_elm; if (dst_elm) - dst = dst_elm->node; + dst = dst_elm; /* add nodes if they don't exist in the graph */ if (src_id == dst_id && src == nullptr && dst == nullptr) { @@ -139,11 +137,11 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_); /* Use the graph_node id mapping set to quickly find the nodes */ - graph_node_map_element_t src_elm = nodeMapSearch(src_id); - graph_node_map_element_t dst_elm = nodeMapSearch(dst_id); + xbt_node_t src_elm = nodeMapSearch(src_id); + xbt_node_t dst_elm = nodeMapSearch(dst_id); - int src_node_id = static_cast(xbt_graph_node_get_data(src_elm->node))->graph_id; - int dst_node_id = static_cast(xbt_graph_node_get_data(dst_elm->node))->graph_id; + int src_node_id = static_cast(xbt_graph_node_get_data(src_elm))->graph_id; + int dst_node_id = static_cast(xbt_graph_node_get_data(dst_elm))->graph_id; /* if the src and dst are the same */ if (src_node_id == dst_node_id) { diff --git a/src/kernel/routing/DijkstraZone.hpp b/src/kernel/routing/DijkstraZone.hpp index e627d5dd6d..5720cd6d4f 100644 --- a/src/kernel/routing/DijkstraZone.hpp +++ b/src/kernel/routing/DijkstraZone.hpp @@ -14,11 +14,6 @@ struct s_graph_node_data_t { }; typedef s_graph_node_data_t* graph_node_data_t; -struct s_graph_node_map_element_t { - xbt_node_t node; -}; -typedef s_graph_node_map_element_t* graph_node_map_element_t; - struct s_route_cache_element_t { int* pred_arr; int size; @@ -48,7 +43,7 @@ public: ~DijkstraZone() override; xbt_node_t routeGraphNewNode(int id, int graph_id); - graph_node_map_element_t nodeMapSearch(int id); + xbt_node_t nodeMapSearch(int id); void newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_route); /* For each vertex (node) already in the graph, * make sure it also has a loopback link; this loopback @@ -65,7 +60,7 @@ public: void addRoute(sg_platf_route_cbarg_t route) override; xbt_graph_t routeGraph_ = nullptr; /* xbt_graph */ - std::map graphNodeMap_; /* map */ + std::map graphNodeMap_; /* map */ std::map routeCache_; /* use in cache mode */ }; }