From 0dc74a05dbbd22d64859dfe818afd09e636662b6 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 12 Oct 2017 10:42:21 +0200 Subject: [PATCH] kill another dict in instr --- .../trace-process-migration.tesh | 12 +++---- src/instr/instr_paje_types.cpp | 21 ++++------- src/instr/instr_private.hpp | 2 +- src/surf/instr_routing.cpp | 35 ++++++------------- 4 files changed, 23 insertions(+), 47 deletions(-) diff --git a/examples/msg/trace-process-migration/trace-process-migration.tesh b/examples/msg/trace-process-migration/trace-process-migration.tesh index 11594a19b3..41a7064990 100644 --- a/examples/msg/trace-process-migration/trace-process-migration.tesh +++ b/examples/msg/trace-process-migration/trace-process-migration.tesh @@ -707,8 +707,8 @@ $ tail -n +3 procmig.trace > 16 0 17 0 topology 21 44 > 15 0 17 0 topology 30 45 > 16 0 17 0 topology 28 45 -> 1 20 13 bmigration_order "0.800026 0.545312 0.857926" -> 1 21 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 20 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 21 13 bmigration_order "0.800026 0.545312 0.857926" > 6 0 32 4 3 "emigrant-1" > 6 0 33 4 1 "policeman-2" > 12 0 5 32 7 @@ -1309,8 +1309,8 @@ $ tail -n +3 procmig.trace > 16 0 17 0 topology 21 44 > 15 0 17 0 topology 30 45 > 16 0 17 0 topology 28 45 -> 1 20 13 bmigration_order "0.800026 0.545312 0.857926" -> 1 21 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 20 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 21 13 bmigration_order "0.800026 0.545312 0.857926" > 6 0 32 4 3 "emigrant-1" > 6 0 33 4 1 "policeman-2" > 12 0 5 32 7 @@ -1900,8 +1900,8 @@ $ tail -n +3 simgrid.trace > 16 0 6 0 topology 21 44 > 15 0 6 0 topology 30 45 > 16 0 6 0 topology 28 45 -> 1 9 3 bmigration_order "0.800026 0.545312 0.857926" -> 1 10 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 9 1 pmigration_order "0.800026 0.545312 0.857926" +> 1 10 3 bmigration_order "0.800026 0.545312 0.857926" > 7 18.155073 3 16 > 7 18.155073 3 14 > 7 18.155073 3 19 diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index 86846ff1a3..abc3104466 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -24,29 +24,23 @@ simgrid::instr::Type::Type(const char* typeNameBuff, const char* key, std::strin } this->name_ = xbt_strdup(typeNameBuff); - this->children_ = xbt_dict_new_homogeneous(nullptr); - this->id_ = bprintf("%lld", instr_new_paje_id()); if (father != nullptr){ - xbt_dict_set(father->children_, key, this, nullptr); + father->children_.insert({key, this}); XBT_DEBUG("new type %s, child of %s", typeNameBuff, father->name_); } } simgrid::instr::Type::~Type() { - xbt_dict_cursor_t cursor = nullptr; for (auto elm : values_) { XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->name_); delete elm.second; } - simgrid::instr::Type* child; - char *child_name; - xbt_dict_foreach (children_, cursor, child_name, child) { - delete child; + for (auto elm : children_) { + delete elm.second; } - xbt_dict_free(&children_); xbt_free(name_); xbt_free(id_); } @@ -64,15 +58,12 @@ simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(const char* name) xbt_assert(name != nullptr, "can't get type with a nullptr name"); simgrid::instr::Type* ret = nullptr; - simgrid::instr::Type* child; - char *child_name; - xbt_dict_cursor_t cursor = nullptr; - xbt_dict_foreach (children_, cursor, child_name, child) { - if (strcmp(child->name_, name) == 0) { + for (auto elm : children_) { + if (strcmp(elm.second->name_, name) == 0) { if (ret != nullptr) { THROWF (tracing_error, 0, "there are two children types with the same name?"); } else { - ret = child; + ret = elm.second; } } } diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index caea5fe1ae..2af3f1825b 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -65,7 +65,7 @@ public: e_entity_types kind_; Type* father_; - xbt_dict_t children_; + std::map children_; std::map values_; // valid for all types except variable and container Type(const char* typeNameBuff, const char* key, std::string color, e_entity_types kind, Type* father); ~Type(); diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index ecbacce3de..ba7a057fdf 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -340,11 +340,8 @@ static void recursiveNewVariableType(const char* new_typename, const char* color snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename); simgrid::instr::Type::variableNew(tnstr, color == nullptr ? "" : color, root); } - xbt_dict_cursor_t cursor = nullptr; - simgrid::instr::Type* child_type; - char *name; - xbt_dict_foreach (root->children_, cursor, name, child_type) { - recursiveNewVariableType(new_typename, color == nullptr ? "" : color, child_type); + for (auto elm : root->children_) { + recursiveNewVariableType(new_typename, color == nullptr ? "" : color, elm.second); } } @@ -359,12 +356,8 @@ static void recursiveNewUserVariableType(const char* father_type, const char* ne if (not strcmp(root->name_, father_type)) { simgrid::instr::Type::variableNew(new_typename, color == nullptr ? "" : color, root); } - xbt_dict_cursor_t cursor = nullptr; - simgrid::instr::Type* child_type; - char *name; - xbt_dict_foreach (root->children_, cursor, name, child_type) { - recursiveNewUserVariableType (father_type, new_typename, color, child_type); - } + for (auto elm : root->children_) + recursiveNewUserVariableType(father_type, new_typename, color, elm.second); } void instr_new_user_variable_type (const char *father_type, const char *new_typename, const char *color) @@ -377,12 +370,8 @@ static void recursiveNewUserStateType(const char* father_type, const char* new_t if (not strcmp(root->name_, father_type)) { simgrid::instr::Type::stateNew(new_typename, root); } - xbt_dict_cursor_t cursor = nullptr; - simgrid::instr::Type* child_type; - char *name; - xbt_dict_foreach (root->children_, cursor, name, child_type) { - recursiveNewUserStateType (father_type, new_typename, child_type); - } + for (auto elm : root->children_) + recursiveNewUserStateType(father_type, new_typename, elm.second); } void instr_new_user_state_type (const char *father_type, const char *new_typename) @@ -393,15 +382,11 @@ void instr_new_user_state_type (const char *father_type, const char *new_typenam static void recursiveNewValueForUserStateType(const char* type_name, const char* val, const char* color, simgrid::instr::Type* root) { - if (not strcmp(root->name_, type_name)) { + if (not strcmp(root->name_, type_name)) simgrid::instr::Value::byNameOrCreate(val, color, root); - } - xbt_dict_cursor_t cursor = nullptr; - simgrid::instr::Type* child_type; - char *name; - xbt_dict_foreach (root->children_, cursor, name, child_type) { - recursiveNewValueForUserStateType(type_name, val, color, child_type); - } + + for (auto elm : root->children_) + recursiveNewValueForUserStateType(type_name, val, color, elm.second); } void instr_new_value_for_user_state_type (const char *type_name, const char *value, const char *color) -- 2.20.1