Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
optimize perf - part 2
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 21:12:44 +0000 (22:12 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 21:12:44 +0000 (22:12 +0100)
include/simgrid/s4u/NetZone.hpp
src/bindings/java/jmsg_as.cpp
src/msg/msg_environment.cpp
src/s4u/s4u_netzone.cpp

index d04ad90..dd1f5e1 100644 (file)
@@ -40,6 +40,7 @@ protected:
 
   explicit NetZone(NetZone * father, const char* name);
   virtual ~NetZone();
+  std::vector<Host*>* hosts_ = nullptr;
 
 public:
   /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
@@ -48,7 +49,7 @@ public:
   NetZone* father();
 
   xbt_dict_t children(); // Sub netzones
-  std::vector<Host*> hosts(); // my content as a vector of hosts
+  std::vector<Host*>* hosts(); // my content as a vector of hosts
 
   /** Get the properties assigned to a host */
   std::unordered_map<std::string, std::string>* properties();
index 57bc735..d814976 100644 (file)
@@ -132,11 +132,11 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo
   simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
 
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
-  std::vector<sg_host_t> table = as->hosts();
+  std::vector<sg_host_t>* table = as->hosts();
   if (!cls)
     return nullptr;
 
-  jtable = env->NewObjectArray(static_cast<jsize>(table.size()), cls, nullptr);
+  jtable = env->NewObjectArray(static_cast<jsize>(table->size()), cls, nullptr);
 
   if (!jtable) {
     jxbt_throw_jni(env, "Hosts table allocation failed");
@@ -144,7 +144,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo
   }
 
   int index = 0;
-  for (auto host : table) {
+  for (auto host : *table) {
     jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
     if (!jhost) {
       jname = env->NewStringUTF(host->cname());
index 733814c..65a7a8c 100644 (file)
@@ -82,7 +82,7 @@ xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t netzone)
 {
   xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
 
-  for (auto host : netzone->hosts()) {
+  for (auto host : *netzone->hosts()) {
     xbt_dynar_push(res, &host);
   }
 
index 5377233..153be09 100644 (file)
@@ -23,7 +23,13 @@ simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kern
 
 NetZone::NetZone(NetZone* father, const char* name) : father_(father), name_(xbt_strdup(name))
 {
+  for (auto card : vertices_) {
+    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
+    if (host != nullptr)
+      hosts_->push_back(host);
+  }
 }
+
 void NetZone::seal()
 {
   sealed_ = true;
@@ -72,16 +78,9 @@ NetZone* NetZone::father()
   return father_;
 }
 
-std::vector<s4u::Host*> NetZone::hosts()
+std::vector<s4u::Host*>* NetZone::hosts()
 {
-  std::vector<s4u::Host*> res;
-
-  for (auto card : vertices_) {
-    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
-    if (host != nullptr)
-      res.push_back(host);
-  }
-  return res;
+  return hosts_;
 }
 
 int NetZone::addComponent(kernel::routing::NetPoint* elm)