1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

bookmarks: Turn tree_node::attrs into a struct list_head.

Previously, it was a pointer to a separately allocated struct attributes,
of which only the LIST_HEAD members were actually used.
All init_list calls now operate on struct list_head.
This change may also reduce memory usage for reading bookmarks.
This commit is contained in:
Kalle Olavi Niemitalo 2006-05-28 18:58:02 +03:00 committed by Miciah Dashiel Butler Masters
parent d6d72a6ff5
commit 403a4ac2a2

View File

@ -49,7 +49,7 @@ static struct tree_node *new_node(struct tree_node *parent);
static void free_node(struct tree_node *node);
static void free_xbeltree(struct tree_node *node);
static struct tree_node *get_child(struct tree_node *node, unsigned char *name);
static unsigned char *get_attribute_value(struct attributes *attr,
static unsigned char *get_attribute_value(struct tree_node *node,
unsigned char *name);
@ -67,7 +67,7 @@ static void write_bookmarks_xbel(struct secure_save_info *ssi,
struct tree_node {
unsigned char *name; /* Name of the element */
unsigned char *text; /* Text inside the element */
struct attributes *attrs; /* Attributes of the element */
struct list_head attrs; /* {struct attributes} */
struct tree_node *parent;
struct tree_node *children;
@ -301,7 +301,7 @@ on_element_open(void *data, const char *name, const char **attr)
attribute->name = tmp;
add_to_list(*current_node->attrs, attribute);
add_to_list(current_node->attrs, attribute);
++attr;
}
@ -382,7 +382,7 @@ xbeltree_to_bookmarks_list(struct tree_node *node,
unsigned char *href;
title = get_child(node, "title");
href = get_attribute_value(node->attrs, "href");
href = get_attribute_value(node, "href");
tmp = add_bookmark(current_parent, 0,
/* The <title> element is optional */
@ -414,7 +414,7 @@ xbeltree_to_bookmarks_list(struct tree_node *node,
/* Out of memory */
if (!tmp) return 0;
folded = get_attribute_value(node->attrs, "folded");
folded = get_attribute_value(node, "folded");
if (folded && !strcmp(folded, "no"))
tmp->box_item->expanded = 1;
@ -487,11 +487,11 @@ get_child(struct tree_node *node, unsigned char *name)
}
static unsigned char *
get_attribute_value(struct attributes *attr, unsigned char *name)
get_attribute_value(struct tree_node *node, unsigned char *name)
{
struct attributes *attribute;
foreachback (attribute, *attr) {
foreachback (attribute, node->attrs) {
if (!strcmp(attribute->name, name)) {
return attribute->prev->name;
}
@ -509,14 +509,7 @@ new_node(struct tree_node *parent)
if (!node) return NULL;
node->parent = parent ? parent : node;
node->attrs = mem_calloc(1, sizeof(*node->attrs));
if (!node->attrs) {
mem_free(node);
return NULL;
}
init_list(*node->attrs);
init_list(node->attrs);
return node;
}
@ -526,13 +519,9 @@ free_node(struct tree_node *node)
{
struct attributes *attribute;
if (node->attrs) {
foreachback (attribute, *node->attrs)
mem_free_if(attribute->name);
free_list(*(struct list_head *) node->attrs); /* Don't free list during traversal */
mem_free(node->attrs);
}
foreachback (attribute, node->attrs)
mem_free_if(attribute->name);
free_list(node->attrs); /* Don't free list during traversal */
mem_free_if(node->name);
mem_free_if(node->text);