Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the dynar creation madness in g_r_a_l in recursive case
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 10:28:19 +0000 (11:28 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 10:28:19 +0000 (11:28 +0100)
src/surf/surf_routing.c

index 55e773c..d9e2ee3 100644 (file)
@@ -544,35 +544,28 @@ static void _get_route_and_latency(const char *src, const char *dst,
 
   xbt_assert((e_route_cnt->src_gateway == NULL) ==
       (e_route_cnt->dst_gateway == NULL),
 
   xbt_assert((e_route_cnt->src_gateway == NULL) ==
       (e_route_cnt->dst_gateway == NULL),
-      "bad gateway for route between \"%s\" and \"%s\"", src, dst);
+      "bad gateways for route from \"%s\" to \"%s\"", src, dst);
 
   *links = xbt_dynar_new(global_routing->size_of_link, NULL);
 
 
   *links = xbt_dynar_new(global_routing->size_of_link, NULL);
 
-  /* If source gateway is not our source, we have to recursively find our way up to this point */
-  if (strcmp(src, e_route_cnt->src_gateway)) {
-    xbt_dynar_t route_src;
-
-    _get_route_and_latency(src, e_route_cnt->src_gateway,
-        (links ? &route_src : NULL),
-        latency);
+  char*src_gateway = e_route_cnt->src_gateway;
+  char*dst_gateway = e_route_cnt->dst_gateway;
 
 
-    xbt_dynar_foreach(route_src, cpt, link) {
-      xbt_dynar_push(*links, &link);
-    }
-    xbt_dynar_free(&route_src);
-  }
+  /* If source gateway is not our source, we have to recursively find our way up to this point */
+  if (strcmp(src, src_gateway))
+    _get_route_and_latency(src, src_gateway, links,latency);
 
   xbt_dynar_foreach(e_route_cnt->link_list, cpt, link) {
     xbt_dynar_push(*links, &link);
   }
 
   /* If dest gateway is not our destination, we have to recursively find our way from this point */
 
   xbt_dynar_foreach(e_route_cnt->link_list, cpt, link) {
     xbt_dynar_push(*links, &link);
   }
 
   /* If dest gateway is not our destination, we have to recursively find our way from this point */
-  if (strcmp(e_route_cnt->dst_gateway, dst)) {
+  // FIXME why can't I factorize it the same way than [src;src_gw] without breaking the examples??
+  if (strcmp(dst_gateway, dst)) {
     xbt_dynar_t route_dst;
 
     xbt_dynar_t route_dst;
 
-    _get_route_and_latency(e_route_cnt->dst_gateway, dst,
-        (links ? &route_dst : NULL),
-        latency);
+    _get_route_and_latency(dst_gateway, dst,
+        &route_dst, latency);
 
     xbt_dynar_foreach(route_dst, cpt, link) {
       xbt_dynar_push(*links, &link);
 
     xbt_dynar_foreach(route_dst, cpt, link) {
       xbt_dynar_push(*links, &link);