From 23374c5b3f88a4b96c351be8f2a6f0e332a2f977 Mon Sep 17 00:00:00 2001 From: Lucas Schnorr Date: Mon, 23 Jan 2012 14:01:01 +0100 Subject: [PATCH] [trace] remove recursive get type support, search operations are local in the type hierarchy --- src/instr/instr_paje_types.c | 36 ++++++++++++++++++------------------ src/instr/instr_private.h | 1 + 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/instr/instr_paje_types.c b/src/instr/instr_paje_types.c index c8f0ee2e3f..48320ccadb 100644 --- a/src/instr/instr_paje_types.c +++ b/src/instr/instr_paje_types.c @@ -98,36 +98,36 @@ void PJ_type_free_all (void) } } -static type_t recursiveGetType (const char *name, type_t root) +type_t PJ_type_get (const char *name, type_t father) { - if (name == NULL || root == NULL){ - THROWF (tracing_error, 0, "can't get type with a NULL name (or a NULL father given)"); + type_t ret = PJ_type_get_or_null (name, father); + if (ret == NULL){ + THROWF (tracing_error, 2, "type with name (%s) not found in father type (%s)", name, father->name); } + return ret; +} - if (strcmp (root->name, name) == 0) return root; +type_t PJ_type_get_or_null (const char *name, type_t father) +{ + if (name == NULL || father == NULL){ + THROWF (tracing_error, 0, "can't get type with a NULL name or from a NULL father"); + } - xbt_dict_cursor_t cursor = NULL; - type_t child; + type_t ret = NULL, child; char *child_name; - type_t ret = NULL; - xbt_dict_foreach(root->children, cursor, child_name, child) { - type_t found = recursiveGetType(name, child); - if (found){ - if (ret == NULL){ - ret = found; + xbt_dict_cursor_t cursor = NULL; + xbt_dict_foreach(father->children, cursor, child_name, child) { + if (strcmp (child->name, name) == 0){ + if (ret != NULL){ + THROWF (tracing_error, 0, "there are two children types with the same name?"); }else{ - THROWF(tracing_error, 0, "found two types with the same name"); + ret = child; } } } return ret; } -type_t PJ_type_get (const char *name, type_t father) -{ - return recursiveGetType (name, father); -} - type_t PJ_type_container_new (const char *name, type_t father) { if (name == NULL){ diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index cd3be85cf5..740bd2dab5 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -221,6 +221,7 @@ type_t PJ_type_variable_new (const char *name, const char *color, type_t father) type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest); type_t PJ_type_state_new (const char *name, type_t father); type_t PJ_type_get (const char *name, const type_t father); +type_t PJ_type_get_or_null (const char *name, type_t father); void PJ_type_free (type_t type); void PJ_type_free_all (void); -- 2.20.1