1.1 --- a/ucx/map.c Fri Aug 09 15:29:26 2013 +0200 1.2 +++ b/ucx/map.c Mon Aug 12 14:39:51 2013 +0200 1.3 @@ -89,8 +89,7 @@ 1.4 UcxMapIterator i = ucx_map_iterator(from); 1.5 void *value; 1.6 UCX_MAP_FOREACH(key, value, i) { 1.7 - int ret = ucx_map_put(to, i.cur->key, fnc ? fnc(value, data) : value); 1.8 - if(ret != 0) { 1.9 + if (ucx_map_put(to, key, fnc ? fnc(value, data) : value)) { 1.10 return 1; 1.11 } 1.12 } 1.13 @@ -100,7 +99,7 @@ 1.14 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data) { 1.15 size_t bs = (map->count * 5) >> 1; 1.16 UcxMap *newmap = ucx_map_new(bs > map->size ? bs : map->size); 1.17 - if(newmap == NULL) { 1.18 + if (!newmap) { 1.19 return NULL; 1.20 } 1.21 ucx_map_copy(map, newmap, fnc, data); 1.22 @@ -121,7 +120,7 @@ 1.23 map->allocator->pool, 1.24 map->size, 1.25 sizeof(UcxMapElement*)); 1.26 - if(map->map == NULL) { 1.27 + if (!map->map) { 1.28 *map = oldmap; 1.29 return 1; 1.30 } 1.31 @@ -137,7 +136,7 @@ 1.32 int ucx_map_put(UcxMap *map, UcxKey key, void *data) { 1.33 UcxAllocator *allocator = map->allocator; 1.34 1.35 - if(key.hash == 0) { 1.36 + if (key.hash == 0) { 1.37 key.hash = ucx_hash((char*)key.data, key.len); 1.38 } 1.39 1.40 @@ -145,16 +144,16 @@ 1.41 UcxMapElement *restrict elm = map->map[slot]; 1.42 UcxMapElement *restrict prev = NULL; 1.43 1.44 - while (elm != NULL && elm->key.hash < key.hash) { 1.45 + while (elm && elm->key.hash < key.hash) { 1.46 prev = elm; 1.47 elm = elm->next; 1.48 } 1.49 1.50 - if (elm == NULL || elm->key.hash != key.hash) { 1.51 + if (!elm || elm->key.hash != key.hash) { 1.52 UcxMapElement *e = (UcxMapElement*)allocator->malloc( 1.53 allocator->pool, 1.54 sizeof(UcxMapElement)); 1.55 - if(e == NULL) { 1.56 + if (!e) { 1.57 return -1; 1.58 } 1.59 e->key.data = NULL; 1.60 @@ -167,9 +166,9 @@ 1.61 elm = e; 1.62 } 1.63 1.64 - if(elm->key.data == NULL) { 1.65 + if (!elm->key.data) { 1.66 void *kd = allocator->malloc(allocator->pool, key.len); 1.67 - if (kd == NULL) { 1.68 + if (!kd) { 1.69 return -1; 1.70 } 1.71 memcpy(kd, key.data, key.len); 1.72 @@ -285,31 +284,31 @@ 1.73 int ucx_map_iter_next(UcxMapIterator *i, UcxKey *key, void **elm) { 1.74 UcxMapElement *e = i->cur; 1.75 1.76 - if(e == NULL) { 1.77 + if (e) { 1.78 + e = e->next; 1.79 + } else { 1.80 e = i->map->map[0]; 1.81 - } else { 1.82 - e = e->next; 1.83 } 1.84 1.85 - while(i->index < i->map->size) { 1.86 - if(e != NULL) { 1.87 - if(e->data != NULL) { 1.88 + while (i->index < i->map->size) { 1.89 + if (e) { 1.90 + if (e->data) { 1.91 i->cur = e; 1.92 *elm = e->data; 1.93 *key = e->key; 1.94 - return 0; 1.95 + return 1; 1.96 } 1.97 1.98 e = e->next; 1.99 } else { 1.100 i->index++; 1.101 1.102 - if(i->index < i->map->size) { 1.103 + if (i->index < i->map->size) { 1.104 e = i->map->map[i->index]; 1.105 } 1.106 } 1.107 } 1.108 1.109 - return 1; 1.110 + return 0; 1.111 } 1.112