From 057abe26bb66c87dec76d58c5fde14f67c82d847 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 26 Mar 2012 17:47:37 +0000 Subject: When retrieving attribute values, if the attribute has a single child, said child is a text node, and has a value, then just ref that string and return it. svn path=/trunk/libdom/; revision=13722 --- src/core/attr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core/attr.c') diff --git a/src/core/attr.c b/src/core/attr.c index dc14a93..9db04b6 100644 --- a/src/core/attr.c +++ b/src/core/attr.c @@ -445,7 +445,16 @@ dom_exception _dom_attr_get_value(struct dom_attr *attr, struct dom_node_internal *c; dom_string *value, *temp; dom_exception err; - + + /* Attempt to shortcut for a single text node child with value */ + if ((a->first_child != NULL) && + (a->first_child == a->last_child) && + (a->first_child->type == DOM_TEXT_NODE) && + (a->first_child->value != NULL)) { + *result = dom_string_ref(a->first_child->value); + return DOM_NO_ERR; + } + err = dom_string_create(NULL, 0, &value); if (err != DOM_NO_ERR) { return err; -- cgit v1.2.3