From fe56a3723461b974e106298866fac80757ba9edf Mon Sep 17 00:00:00 2001 From: barbieri Date: Mon, 2 Aug 2010 23:35:30 +0000 Subject: [PATCH] let's stop smoking crack while coding :-P dudes, WTF is that look to check for numbers, then use atoi()??? Use strtol() and let it do both in one pass. Also, just do these for part types that make sense. The loop using child could result in unused variables in lots of cases, returning the wrong value when not found. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@50757 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/edje_util.c | 54 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/lib/edje_util.c b/src/lib/edje_util.c index 3b5365b..c34c6b1 100644 --- a/src/lib/edje_util.c +++ b/src/lib/edje_util.c @@ -4241,35 +4241,45 @@ _edje_children_get(Edje_Real_Part *rp, const char *partid) { Evas_Object *child; Eina_List *l; - Eina_Bool number = EINA_TRUE; - unsigned int i; + long int v; + char *p; - for (i = 0; i < strlen(partid); ++i) - number &= isdigit(partid[i]) ? EINA_TRUE : EINA_FALSE; + if (!partid) return NULL; - if (rp->part->type == EDJE_PART_TYPE_BOX) - l = evas_object_box_children_get(rp->object); - else - if (rp->part->type == EDJE_PART_TYPE_TABLE) - l = evas_object_table_children_get(rp->object); - else - if (rp->part->type == EDJE_PART_TYPE_EXTERNAL) - return _edje_external_content_get(rp->swallowed_object, partid); - else - return NULL; - - if (number) + switch (rp->part->type) + { + case EDJE_PART_TYPE_EXTERNAL: + return _edje_external_content_get(rp->swallowed_object, partid); + case EDJE_PART_TYPE_BOX: + l = evas_object_box_children_get(rp->object); + break; + case EDJE_PART_TYPE_TABLE: + l = evas_object_table_children_get(rp->object); + break; + default: + return NULL; + } + + v = strtol(partid, &p, 10); + if ((*p == '\0') && (v >= 0)) { - child = eina_list_nth(l, atoi(partid)); - eina_list_free(l); + child = eina_list_nth(l, v); } else { - EINA_LIST_FREE(l, child) - if (!strcmp(evas_object_name_get(child), partid)) - break ; - eina_list_free(l); + Evas_Object *cur; + child = NULL; + EINA_LIST_FREE(l, cur) + { + const char *name = evas_object_name_get(cur); + if ((name) && (!strcmp(name, partid))) + { + child = cur; + break; + } + } } + eina_list_free(l); return child; } -- 2.7.4