replace all find != end + at by a try/catch on at.
This should save a useless traversal of the [unordered_]map each time
we want to access an element.
for (int i = 0; i < max; i++) {
if (i <= max_index_src && max <= max_index_dst) {
key = {path_src.at(i)->netpoint_, path_dst.at(max)->netpoint_};
- if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
+ try {
bypassedRoute = bypassRoutes_.at(key);
break;
+ } catch (std::out_of_range& unfound) {
+ // Do nothing
}
}
if (max <= max_index_src && i <= max_index_dst) {
key = {path_src.at(max)->netpoint_, path_dst.at(i)->netpoint_};
- if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
+ try {
bypassedRoute = bypassRoutes_.at(key);
break;
+ } catch (std::out_of_range& unfound) {
+ // Do nothing
}
}
}
if (max <= max_index_src && max <= max_index_dst) {
key = {path_src.at(max)->netpoint_, path_dst.at(max)->netpoint_};
- if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
+ try {
bypassedRoute = bypassRoutes_.at(key);
break;
+ } catch (std::out_of_range& unfound) {
+ // Do nothing
}
}
}
}
/* Retrieve the private links */
- if (privateLinks_.find(src->id()) != privateLinks_.end()) {
+ try {
std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(src->id());
if (info.first) {
route->link_list->push_back(info.first);
if (lat)
*lat += info.first->latency();
}
+ } catch (std::out_of_range& unfound) {
+ XBT_DEBUG("Source of private link (%u) doesn't exist", src->id());
}
- if (privateLinks_.find(dst->id()) != privateLinks_.end()) {
+
+ try {
std::pair<surf::LinkImpl*, surf::LinkImpl*> info = privateLinks_.at(dst->id());
if (info.second) {
route->link_list->push_back(info.second);
if (lat)
*lat += info.second->latency();
}
+ } catch (std::out_of_range& unfound) {
+ XBT_DEBUG("Destination of private link (%u) doesn't exist", dst->id());
}
/* Compute the extra latency due to the euclidean distance if needed */
/** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(const char* name)
{
- if (pimpl->netpoints_.find(name) == pimpl->netpoints_.end())
+ try {
+ return pimpl->netpoints_.at(name);
+ } catch (std::out_of_range& unfound) {
return nullptr;
- return pimpl->netpoints_.at(name);
+ }
}
/** @brief Fill the provided vector with all existing netpoints */
void Engine::getNetpointList(std::vector<simgrid::kernel::routing::NetPoint*>* list)
}
Host* Host::by_name_or_null(std::string name)
{
- if (host_list.find(name) == host_list.end())
+ try {
+ return host_list.at(name);
+ } catch (std::out_of_range& unfound) {
return nullptr;
- return host_list.at(name);
+ }
}
Host *Host::current(){
/** @brief Returns the process from PID. */
smx_actor_t SIMIX_process_from_PID(aid_t PID)
{
- if (simix_global->process_list.find(PID) == simix_global->process_list.end())
+ try {
+ return simix_global->process_list.at(PID);
+ } catch (std::out_of_range& unfound) {
return nullptr;
- return simix_global->process_list.at(PID);
+ }
}
/** @brief returns a dynar containing all currently existing processes */
{
if (this == MPI_GROUP_EMPTY)
return MPI_UNDEFINED;
- if (index_to_rank_map_.find(index) == index_to_rank_map_.end())
- return MPI_UNDEFINED;
- else
+ try {
return index_to_rank_map_.at(index);
+ } catch (std::out_of_range& unfound) {
+ return MPI_UNDEFINED;
+ }
}
void Group::ref()
location_ = st->getImpl();
std::map<std::string, sg_size_t>* content = location_->getContent();
// if file does not exist create an empty file
- if (content->find(path) != content->end())
+ try {
size_ = content->at(path);
- else {
+ } catch (std::out_of_range& unfound) {
size_ = 0;
content->insert({path, size_});
XBT_DEBUG("File '%s' was not found, file created.", path.c_str());
/* Check if the new full path is on the same mount point */
if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) {
std::map<std::string, sg_size_t>* content = location_->getContent();
- if (content->find(path_) != content->end()) { // src file exists
+ try { // src file exists
sg_size_t new_size = content->at(path_);
content->erase(path_);
std::string path = std::string(fullpath).substr(mount_point_.size(), strlen(fullpath));
content->insert({path.c_str(), new_size});
XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath, new_size);
- } else {
+ } catch (std::out_of_range& unfound) {
XBT_WARN("File %s doesn't exist", path_.c_str());
}
} else {
LinkImpl* LinkImpl::byName(const char* name)
{
- if (links->find(name) == links->end())
+ try {
+ return links->at(name);
+ } catch (std::out_of_range& unfound) {
return nullptr;
- return links->at(name);
+ }
}
/** @brief Returns the amount of links in the platform */
int LinkImpl::linksCount()
} else {
// Else, I have to store it for the relevant colleague
std::queue<ReplayAction*>* otherqueue = nullptr;
- if (action_queues.find(evtname) != action_queues.end())
+ try {
otherqueue = action_queues.at(evtname);
- else { // Damn. Create the queue of that guy
+ } catch (std::out_of_range& unfound) { // Damn. Create the queue of that guy
otherqueue = new std::queue<ReplayAction*>();
action_queues.insert({evtname, otherqueue});
}