--- gpl/axl/src/axl_node.c 2011/06/08 07:09:12 1.1.1.1 +++ gpl/axl/src/axl_node.c 2012/02/17 12:50:03 1.1.1.2 @@ -126,6 +126,9 @@ axlNodeAttr * __axl_node_copy_attr_list (axlNodeAttr * /* alloc memory to hold attribute name and value, and * copy it from the list */ result = axl_new (axlNodeAttr, 1); + /* check allocated result */ + if (result == NULL) + return NULL; result->attribute = axl_strdup (list->attribute); result->value = axl_strdup (list->value); @@ -1303,6 +1306,15 @@ axl_bool axl_node_has_attribute (axlNode return axl_hash_exists ((axlHash *) node->attributes, (axlPointer) attribute); } +axl_bool __axl_node_remove_attribute_reinsert (axlPointer key, axlPointer data, axlPointer user_data) +{ + + /* re-add attributes into the node */ + axl_node_set_attribute (user_data, key, data); + + return axl_false; /* do not stop until process all nodes */ +} + /** * @brief Allows to remove the provided attribute, from the node * provided. @@ -1317,6 +1329,7 @@ void axl_node_remove_attribute (axlNode { axlNodeAttr * attr; axlNodeAttr * previous; + axlHash * temp; axl_return_if_fail (node); axl_return_if_fail (attribute); @@ -1348,6 +1361,9 @@ void axl_node_remove_attribute (axlNode axl_free (attr->value); axl_free (attr); } /* end if */ + + /* update attribute count */ + node->attr_num--; return; } @@ -1364,10 +1380,26 @@ void axl_node_remove_attribute (axlNode /* hashed configuration */ axl_hash_remove ((axlHash *) node->attributes, (axlPointer) attribute); - /* do not decrease attribute number - * since it is used to know the kind - * of store used. */ + /* update attributes stored */ + node->attr_num = axl_hash_items ((axlHash *) node->attributes); + + /* if we have fewer than the provided number, rebuild structure */ + if (node->attr_num == 10) { + /* reconvert attribute format */ + temp = (axlHash *) node->attributes; + node->attributes = NULL; + node->attr_num = 0; + + /* reinsert nodes */ + axl_hash_foreach (temp, __axl_node_remove_attribute_reinsert, node); + + /* release hash */ + axl_hash_free (temp); + + printf ("Number of items after reinserting..%d\n", node->attr_num); + } /* end if */ + return; } @@ -1382,24 +1414,10 @@ void axl_node_remove_attribute (axlNode */ int axl_node_num_attributes (axlNode * node) { - int result = 0; - axlNodeAttr * attr; - axl_return_val_if_fail (node, -1); if (node->attr_num <= 10) { - /* linked configuration */ - attr = (axlNodeAttr *) node->attributes; - while (attr != NULL) { - /* update sum */ - result++; - - /* get the next attribute */ - attr = attr->next; - } /* end while */ - - /* attribute not found */ - return result; + return node->attr_num; } /* end if */ /* hashed configuration */