From ffeda6173da70f62490fd56bcaec9de30ed9f362 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 8 Mar 2017 21:48:38 +0100 Subject: [PATCH] optimize performances --- include/simgrid/s4u/host.hpp | 2 +- src/s4u/s4u_host.cpp | 6 ++---- src/simgrid/host.cpp | 5 ++++- src/surf/HostImpl.cpp | 6 ++---- src/surf/HostImpl.hpp | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index 7c48221eb8..77c4a7be32 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -94,7 +94,7 @@ public: void setPstate(int pstate_index); int pstate(); xbt_dict_t mountedStoragesAsDict(); // HACK - std::vector attachedStorages(); + void attachedStorages(std::vector * storages); /** Get an associative list [mount point]->[Storage] of all local mount points. * diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index dcfa890cd1..44999c9fea 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -257,11 +257,9 @@ xbt_dict_t Host::mountedStoragesAsDict() * \brief Returns the list of storages attached to an host. * \return a dict containing all storages attached to the host */ -std::vector Host::attachedStorages() +void Host::attachedStorages(std::vector* storages) { - return simgrid::simix::kernelImmediate([this] { - return this->pimpl_->getAttachedStorageList(); - }); + simgrid::simix::kernelImmediate([this, storages] { this->pimpl_->getAttachedStorageList(storages); }); } } // namespace simgrid diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 51bc85ed23..21f311f00c 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -121,9 +121,12 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){ } xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){ + std::vector* storage_vector = new std::vector(); xbt_dynar_t storage_dynar = xbt_dynar_new(sizeof(const char*), nullptr); - for (auto name : host->attachedStorages()) + host->attachedStorages(storage_vector); + for (auto name : *storage_vector) xbt_dynar_push(storage_dynar, &name); + delete storage_vector; return storage_dynar; } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 5366a5d6fb..edb9499d2c 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -138,23 +138,21 @@ xbt_dict_t HostImpl::getMountedStorageList() return storage_list; } -std::vector HostImpl::getAttachedStorageList() +void HostImpl::getAttachedStorageList(std::vector* storages) { xbt_lib_cursor_t cursor; char* key; void** data; - std::vector result; xbt_lib_foreach(storage_lib, cursor, key, data) { if (xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != nullptr) { simgrid::surf::Storage* storage = static_cast( xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL)); if (!strcmp(static_cast(storage->attach_), piface_->cname())) { - result.push_back(storage->cname()); + storages->push_back(storage->cname()); } } } - return result; } Action* HostImpl::open(const char* fullpath) diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 4c28215202..6180248601 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -73,7 +73,7 @@ public: virtual xbt_dict_t getMountedStorageList(); /** @brief Get the xbt_dynar_t of storages attached to the Host */ - virtual std::vector getAttachedStorageList(); + virtual void getAttachedStorageList(std::vector* storages); /** * @brief Open a file -- 2.20.1