From: Frederic Suter Date: Wed, 8 Mar 2017 21:12:44 +0000 (+0100) Subject: optimize perf - part 2 X-Git-Tag: v3_15~179 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/69b64311b67fddc105da16faded6fecec9db45d3?hp=ffeda6173da70f62490fd56bcaec9de30ed9f362 optimize perf - part 2 --- diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index d04ad90fa9..dd1f5e1422 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -40,6 +40,7 @@ protected: explicit NetZone(NetZone * father, const char* name); virtual ~NetZone(); + std::vector* 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 hosts(); // my content as a vector of hosts + std::vector* hosts(); // my content as a vector of hosts /** Get the properties assigned to a host */ std::unordered_map* properties(); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index 57bc73518a..d814976a69 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -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 table = as->hosts(); + std::vector* table = as->hosts(); if (!cls) return nullptr; - jtable = env->NewObjectArray(static_cast(table.size()), cls, nullptr); + jtable = env->NewObjectArray(static_cast(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(host->extension(JAVA_HOST_LEVEL)); if (!jhost) { jname = env->NewStringUTF(host->cname()); diff --git a/src/msg/msg_environment.cpp b/src/msg/msg_environment.cpp index 733814c377..65a7a8ccba 100644 --- a/src/msg/msg_environment.cpp +++ b/src/msg/msg_environment.cpp @@ -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); } diff --git a/src/s4u/s4u_netzone.cpp b/src/s4u/s4u_netzone.cpp index 5377233560..153be093f9 100644 --- a/src/s4u/s4u_netzone.cpp +++ b/src/s4u/s4u_netzone.cpp @@ -23,7 +23,13 @@ simgrid::xbt::signalname()); + if (host != nullptr) + hosts_->push_back(host); + } } + void NetZone::seal() { sealed_ = true; @@ -72,16 +78,9 @@ NetZone* NetZone::father() return father_; } -std::vector NetZone::hosts() +std::vector* NetZone::hosts() { - std::vector 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)