chaning to iterative implelementation of find
authorvb
Wed, 11 Mar 2015 15:17:26 +0100
changeset 104709edbd8f9c1
parent 103 5bff3b143e3e
child 105 bdd627440076
chaning to iterative implelementation of find
src/stringpair.c
src/stringpair.h
     1.1 --- a/src/stringpair.c	Wed Mar 11 12:28:09 2015 +0100
     1.2 +++ b/src/stringpair.c	Wed Mar 11 15:17:26 2015 +0100
     1.3 @@ -159,19 +159,19 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -DYNAMIC_API stringpair_t *stringpair_list_find(
     1.8 +DYNAMIC_API stringpair_list_t *stringpair_list_find(
     1.9          stringpair_list_t *stringpair_list,
    1.10          const char *key
    1.11      )
    1.12  {
    1.13      assert(key);
    1.14  
    1.15 -    if (stringpair_list == NULL)
    1.16 -        return NULL;
    1.17 +    stringpair_list_t *_l;
    1.18 +    for (_l = stringpair_list; _l; _l = _l->next) {
    1.19 +        if (strcoll(key, _l->value->key) == 0)
    1.20 +            return _l;
    1.21 +    }
    1.22  
    1.23 -    if (strcoll(stringpair_list->value->key, key) == 0)
    1.24 -        return stringpair_list->value;
    1.25 -    else
    1.26 -        return stringpair_list_find(stringpair_list->next, key);
    1.27 +    return NULL;
    1.28  }
    1.29  
     2.1 --- a/src/stringpair.h	Wed Mar 11 12:28:09 2015 +0100
     2.2 +++ b/src/stringpair.h	Wed Mar 11 15:17:26 2015 +0100
     2.3 @@ -149,9 +149,9 @@
     2.4  //      key (in)                key to search for
     2.5  //
     2.6  //  return value:
     2.7 -//      stringpair_t if found or NULL if not
     2.8 +//      node with result if found or NULL if not
     2.9  
    2.10 -DYNAMIC_API stringpair_t *stringpair_list_find(
    2.11 +DYNAMIC_API stringpair_list_t *stringpair_list_find(
    2.12          stringpair_list_t *stringpair_list,
    2.13          const char *key
    2.14      );