mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -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:
parent
d6d72a6ff5
commit
403a4ac2a2
@ -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_node(struct tree_node *node);
|
||||||
static void free_xbeltree(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 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);
|
unsigned char *name);
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ static void write_bookmarks_xbel(struct secure_save_info *ssi,
|
|||||||
struct tree_node {
|
struct tree_node {
|
||||||
unsigned char *name; /* Name of the element */
|
unsigned char *name; /* Name of the element */
|
||||||
unsigned char *text; /* Text inside 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 *parent;
|
||||||
struct tree_node *children;
|
struct tree_node *children;
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ on_element_open(void *data, const char *name, const char **attr)
|
|||||||
|
|
||||||
attribute->name = tmp;
|
attribute->name = tmp;
|
||||||
|
|
||||||
add_to_list(*current_node->attrs, attribute);
|
add_to_list(current_node->attrs, attribute);
|
||||||
|
|
||||||
++attr;
|
++attr;
|
||||||
}
|
}
|
||||||
@ -382,7 +382,7 @@ xbeltree_to_bookmarks_list(struct tree_node *node,
|
|||||||
unsigned char *href;
|
unsigned char *href;
|
||||||
|
|
||||||
title = get_child(node, "title");
|
title = get_child(node, "title");
|
||||||
href = get_attribute_value(node->attrs, "href");
|
href = get_attribute_value(node, "href");
|
||||||
|
|
||||||
tmp = add_bookmark(current_parent, 0,
|
tmp = add_bookmark(current_parent, 0,
|
||||||
/* The <title> element is optional */
|
/* The <title> element is optional */
|
||||||
@ -414,7 +414,7 @@ xbeltree_to_bookmarks_list(struct tree_node *node,
|
|||||||
/* Out of memory */
|
/* Out of memory */
|
||||||
if (!tmp) return 0;
|
if (!tmp) return 0;
|
||||||
|
|
||||||
folded = get_attribute_value(node->attrs, "folded");
|
folded = get_attribute_value(node, "folded");
|
||||||
if (folded && !strcmp(folded, "no"))
|
if (folded && !strcmp(folded, "no"))
|
||||||
tmp->box_item->expanded = 1;
|
tmp->box_item->expanded = 1;
|
||||||
|
|
||||||
@ -487,11 +487,11 @@ get_child(struct tree_node *node, unsigned char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *
|
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;
|
struct attributes *attribute;
|
||||||
|
|
||||||
foreachback (attribute, *attr) {
|
foreachback (attribute, node->attrs) {
|
||||||
if (!strcmp(attribute->name, name)) {
|
if (!strcmp(attribute->name, name)) {
|
||||||
return attribute->prev->name;
|
return attribute->prev->name;
|
||||||
}
|
}
|
||||||
@ -509,14 +509,7 @@ new_node(struct tree_node *parent)
|
|||||||
if (!node) return NULL;
|
if (!node) return NULL;
|
||||||
|
|
||||||
node->parent = parent ? parent : node;
|
node->parent = parent ? parent : node;
|
||||||
|
init_list(node->attrs);
|
||||||
node->attrs = mem_calloc(1, sizeof(*node->attrs));
|
|
||||||
if (!node->attrs) {
|
|
||||||
mem_free(node);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_list(*node->attrs);
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -526,13 +519,9 @@ free_node(struct tree_node *node)
|
|||||||
{
|
{
|
||||||
struct attributes *attribute;
|
struct attributes *attribute;
|
||||||
|
|
||||||
if (node->attrs) {
|
foreachback (attribute, node->attrs)
|
||||||
foreachback (attribute, *node->attrs)
|
mem_free_if(attribute->name);
|
||||||
mem_free_if(attribute->name);
|
free_list(node->attrs); /* Don't free list during traversal */
|
||||||
|
|
||||||
free_list(*(struct list_head *) node->attrs); /* Don't free list during traversal */
|
|
||||||
mem_free(node->attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
mem_free_if(node->name);
|
mem_free_if(node->name);
|
||||||
mem_free_if(node->text);
|
mem_free_if(node->text);
|
||||||
|
Loading…
Reference in New Issue
Block a user