From: Martin Quinson Date: Thu, 9 Mar 2017 11:04:02 +0000 (+0100) Subject: prefer the stack to the heap (+ don't refill the host list if already full) X-Git-Tag: v3_15~176 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/22b73e951cc052e33689b42fd9a747334bc22c8a prefer the stack to the heap (+ don't refill the host list if already full) --- diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 38cfab22c4..c05a251082 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -40,7 +40,7 @@ protected: explicit NetZone(NetZone * father, const char* name); virtual ~NetZone(); - std::vector* hosts_ = new std::vector(); + std::vector hosts_; public: /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */ diff --git a/src/s4u/s4u_netzone.cpp b/src/s4u/s4u_netzone.cpp index 780baadf35..0a343db706 100644 --- a/src/s4u/s4u_netzone.cpp +++ b/src/s4u/s4u_netzone.cpp @@ -38,7 +38,6 @@ NetZone::~NetZone() delete static_cast(elem); } - delete hosts_; xbt_dict_free(&children_); xbt_free(name_); } @@ -76,12 +75,13 @@ NetZone* NetZone::father() std::vector* NetZone::hosts() { - for (auto card : vertices_) { - s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name()); - if (host != nullptr) - hosts_->push_back(host); - } - return hosts_; + if (hosts_.empty()) // Lazy initialization + for (auto card : vertices_) { + s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name()); + if (host != nullptr) + hosts_.push_back(host); + } + return &hosts_; } int NetZone::addComponent(kernel::routing::NetPoint* elm)