From 808745d358295b6534b2c472b29cffa2b29d1b18 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 1 Mar 2016 11:23:28 +0100 Subject: [PATCH 1/1] use std::pair instead of bprintf(%s#%s)ing the keys --- src/simdag/sd_global.cpp | 3 +-- src/surf/surf_routing.cpp | 38 +++++++++++++++----------------------- src/surf/surf_routing.hpp | 2 +- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/simdag/sd_global.cpp b/src/simdag/sd_global.cpp index f8b6d504e9..a9e2f60a5e 100644 --- a/src/simdag/sd_global.cpp +++ b/src/simdag/sd_global.cpp @@ -50,8 +50,7 @@ void SD_init(int *argc, char **argv) surf_init(argc, argv); - xbt_cfg_setdefault_string(_sg_cfg_set, "host/model", - "ptask_L07"); + xbt_cfg_setdefault_string(_sg_cfg_set, "host/model", "ptask_L07"); #ifdef HAVE_JEDULE jedule_sd_init(); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index dffa3dc852..eef8fe46c7 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -132,12 +132,10 @@ namespace surf { std::vector *bypassedRoute = nullptr; if(dst->containingAS() == this && src->containingAS() == this ){ - char *route_name = bprintf("%s#%s", src->name(), dst->name()); - if (bypassRoutes_.find(route_name) != bypassRoutes_.end()) { - bypassedRoute = bypassRoutes_.at(route_name); + if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) { + bypassedRoute = bypassRoutes_.at({src->name(),dst->name()}); XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size()); } - free(route_name); return bypassedRoute; } @@ -171,18 +169,16 @@ namespace surf { for (int max = 0; max <= max_index; max++) { for (int i = 0; i < max; i++) { if (i <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", path_src.at(i)->name_, path_dst.at(max)->name_); - if (bypassRoutes_.find(route_name) != bypassRoutes_.end()) - bypassedRoute = bypassRoutes_.at(route_name); - xbt_free(route_name); + const std::pair key = {path_src.at(i)->name_, path_dst.at(max)->name_}; + if (bypassRoutes_.find(key) != bypassRoutes_.end()) + bypassedRoute = bypassRoutes_.at(key); } if (bypassedRoute) break; if (max <= max_index_src && i <= max_index_dst) { - char *route_name = bprintf("%s#%s", path_src.at(max)->name_, path_dst.at(i)->name_); - if (bypassRoutes_.find(route_name) != bypassRoutes_.end()) - bypassedRoute = bypassRoutes_.at(route_name); - xbt_free(route_name); + const std::pair key = {path_src.at(max)->name_, path_dst.at(i)->name_}; + if (bypassRoutes_.find(key) != bypassRoutes_.end()) + bypassedRoute = bypassRoutes_.at(key); } if (bypassedRoute) break; @@ -192,10 +188,9 @@ namespace surf { break; if (max <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", path_src.at(max)->name_, path_dst.at(max)->name_); - if (bypassRoutes_.find(route_name) != bypassRoutes_.end()) - bypassedRoute = bypassRoutes_.at(route_name); - xbt_free(route_name); + const std::pair key = {path_src.at(max)->name_, path_dst.at(max)->name_}; + if (bypassRoutes_.find(key) != bypassRoutes_.end()) + bypassedRoute = bypassRoutes_.at(key); } if (bypassedRoute) break; @@ -208,20 +203,18 @@ namespace surf { const char *src = e_route->src; const char *dst = e_route->dst; - char *route_name = bprintf("%s#%s", src, dst); - /* Argument validity checks */ if (e_route->gw_dst) { XBT_DEBUG("Load bypassASroute from %s@%s to %s@%s", src, e_route->gw_src->name(), dst, e_route->gw_dst->name()); xbt_assert(!e_route->link_list->empty(), "Bypass route between %s@%s and %s@%s cannot be empty.", src, e_route->gw_src->name(), dst, e_route->gw_dst->name()); - xbt_assert(bypassRoutes_.find(route_name) == bypassRoutes_.end(), "The bypass route between %s@%s and %s@%s already exists.", + xbt_assert(bypassRoutes_.find({src,dst}) == bypassRoutes_.end(), "The bypass route between %s@%s and %s@%s already exists.", src, e_route->gw_src->name(), dst, e_route->gw_dst->name()); } else { XBT_DEBUG("Load bypassRoute from %s to %s", src, dst); - xbt_assert(!e_route->link_list->empty(), "Bypass route between %s and %s cannot be empty.", src, dst); - xbt_assert(bypassRoutes_.find(route_name) == bypassRoutes_.end(), "The bypass route between %s and %s already exists.", src, dst); + xbt_assert(!e_route->link_list->empty(), "Bypass route between %s and %s cannot be empty.", src, dst); + xbt_assert(bypassRoutes_.find({src,dst}) == bypassRoutes_.end(), "The bypass route between %s and %s already exists.", src, dst); } /* Build a copy that will be stored in the dict */ @@ -230,8 +223,7 @@ namespace surf { newRoute->push_back(link); /* Store it */ - bypassRoutes_.insert({route_name, newRoute}); - xbt_free(route_name); + bypassRoutes_.insert({{src,dst}, newRoute}); } }} // namespace simgrid::surf diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 8d091fe1e7..6007faf4c9 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -75,7 +75,7 @@ private: bool sealed_ = false; // We cannot add more content when sealed friend RoutingPlatf; - std::map*> bypassRoutes_; + std::map, std::vector*> bypassRoutes_; // srcName x dstName -> route static void getRouteRecursive(NetCard *src, NetCard *dst, /* OUT */ std::vector * links, double *latency); std::vector *getBypassRoute(NetCard *src, NetCard *dst); -- 2.20.1