Author: jmb
Date: Sun May 22 06:17:26 2011
New Revision: 12441
URL:
http://source.netsurf-browser.org?rev=12441&view=rev
Log:
Make element.c compile again
Modified:
branches/jmb/dom-alloc-purge/src/core/document.h
branches/jmb/dom-alloc-purge/src/core/element.c
branches/jmb/dom-alloc-purge/src/core/element.h
Modified: branches/jmb/dom-alloc-purge/src/core/document.h
URL:
http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/d...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/document.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/document.h Sun May 22 06:17:26 2011
@@ -56,7 +56,7 @@
struct list_entry pending_nodes;
/**< The deletion pending list */
- struct lwc_string_s *id_name; /**< The ID attribute's name */
+ dom_string *id_name; /**< The ID attribute's name */
dom_document_event_internal dei;
/**< The DocumentEVent interface */
@@ -240,8 +240,8 @@
/* Get a nodelist, creating one if necessary */
dom_exception _dom_document_get_nodelist(struct dom_document *doc,
nodelist_type type, struct dom_node_internal *root,
- struct lwc_string_s *tagname, struct lwc_string_s *namespace,
- struct lwc_string_s *localname, struct dom_nodelist **list);
+ dom_string *tagname, dom_string *namespace,
+ dom_string *localname, struct dom_nodelist **list);
/* Remove a nodelist */
void _dom_document_remove_nodelist(struct dom_document *doc,
struct dom_nodelist *list);
Modified: branches/jmb/dom-alloc-purge/src/core/element.c
URL:
http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.c (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.c Sun May 22 06:17:26 2011
@@ -180,14 +180,14 @@
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &el->attributes);
+ (dom_hash_func) dom_string_hash, &el->attributes);
if (err != DOM_NO_ERR) {
free(el);
return err;
}
err = _dom_document_create_hashtable(doc, CHAINS_NAMESPACE,
- _dom_hash_hash_lwcstring, &el->ns_attributes);
+ (dom_hash_func) dom_string_hash, &el->ns_attributes);
if (err != DOM_NO_ERR) {
free(el->attributes);
free(el);
@@ -214,20 +214,19 @@
/**
* Finalise a dom_element
*
- * \param doc The document
* \param ele The element
*/
-void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele)
+void _dom_element_finalise(struct dom_element *ele)
{
/* Destroy attributes attached to this node */
if (ele->attributes != NULL) {
- _dom_hash_destroy(ele->attributes, _key, NULL, _value, doc);
+ _dom_hash_destroy(ele->attributes, _key, NULL, _value, NULL);
ele->attributes = NULL;
}
if (ele->ns_attributes != NULL) {
_dom_hash_destroy(ele->ns_attributes, _key, NULL,
- _nsattributes, doc);
+ _nsattributes, NULL);
ele->ns_attributes = NULL;
}
@@ -242,15 +241,13 @@
/**
* Destroy an element
*
- * \param doc The owning document
* \param element The element to destroy
*
* The contents of ::element will be destroyed and ::element will be freed.
*/
-void _dom_element_destroy(struct dom_document *doc,
- struct dom_element *element)
-{
- _dom_element_finalise(doc, element);
+void _dom_element_destroy(struct dom_element *element)
+{
+ _dom_element_finalise(element);
/* Free the element */
free(element);
@@ -442,19 +439,12 @@
dom_string *namespace, dom_string *localname,
dom_string **value)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL)
return _dom_element_get_attribute(element, localname, value);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*value = NULL;
@@ -497,7 +487,6 @@
dom_string *namespace, dom_string *qname,
dom_string *value)
{
- lwc_string *str;
dom_exception err;
struct dom_hash_table *attrs;
bool added;
@@ -524,23 +513,18 @@
return err;
}
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
dom_document *doc;
doc = dom_node_get_owner(element);
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_NS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &attrs);
+ (dom_hash_func) dom_string_hash, &attrs);
if (err != DOM_NO_ERR)
return err;
- added = _dom_hash_add(element->ns_attributes, str, attrs,
+ added = _dom_hash_add(element->ns_attributes, namespace, attrs,
false);
if (added == false)
return DOM_NO_MEM_ERR;
@@ -566,19 +550,12 @@
dom_exception _dom_element_remove_attribute_ns(struct dom_element *element,
dom_string *namespace, dom_string *localname)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace != NULL)
return _dom_element_remove_attribute(element, localname);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
return DOM_NO_ERR;
@@ -608,8 +585,6 @@
dom_string *namespace, dom_string *localname,
struct dom_attr **result)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL) {
@@ -617,12 +592,7 @@
result);
}
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*result = NULL;
@@ -657,7 +627,6 @@
dom_exception _dom_element_set_attribute_node_ns(struct dom_element *element,
struct dom_attr *attr, struct dom_attr **result)
{
- lwc_string *str;
dom_exception err;
struct dom_hash_table *attrs;
bool added;
@@ -670,23 +639,18 @@
if (namespace == NULL)
return _dom_element_set_attribute_node(element, attr, result);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
dom_document *doc;
doc = dom_node_get_owner(element);
assert(doc != NULL);
err = _dom_document_create_hashtable(doc, CHAINS_NS_ATTRIBUTES,
- _dom_hash_hash_lwcstring, &attrs);
+ (dom_hash_func) dom_string_hash, &attrs);
if (err != DOM_NO_ERR)
return err;
- added = _dom_hash_add(element->ns_attributes, str, attrs,
+ added = _dom_hash_add(element->ns_attributes, namespace, attrs,
false);
if (added == false)
return DOM_NO_MEM_ERR;
@@ -728,31 +692,11 @@
/** \todo ensure XML feature is supported */
- /* Get the interned string from the dom_string */
- lwc_string *l = NULL, *n = NULL;
- if (localname != NULL) {
- err = _dom_string_intern(localname, &l);
- if (err != DOM_NO_ERR)
- return err;
- }
- if (namespace != NULL) {
- err = _dom_string_intern(namespace, &n);
- if (err != DOM_NO_ERR) {
- lwc_string_unref(l);
-
- return err;
- }
- }
-
err = _dom_document_get_nodelist(element->base.owner,
DOM_NODELIST_BY_NAMESPACE,
- (struct dom_node_internal *) element, NULL, n, l,
+ (struct dom_node_internal *) element, NULL,
+ namespace, localname,
result);
-
- if (localname != NULL)
- lwc_string_unref(l);
- if (namespace != NULL)
- lwc_string_unref(n);
return err;
}
@@ -790,19 +734,12 @@
dom_string *namespace, dom_string *localname,
bool *result)
{
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *attrs;
if (namespace == NULL)
return _dom_element_has_attribute(element, localname, result);
- err = _dom_node_get_intern_string(&element->base, namespace, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attrs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- str);
+ attrs = _dom_hash_get(element->ns_attributes, namespace);
/* The element has no such namespace */
if (attrs == NULL) {
*result = false;
@@ -872,24 +809,18 @@
{
struct dom_hash_table *hs;
dom_exception err;
- lwc_string *ns;
if (namespace == NULL)
return _dom_element_set_id_attribute(element, localname, is_id);
- err = _dom_node_get_intern_string(&element->base, namespace, &ns);
+ hs = _dom_hash_get(element->ns_attributes, namespace);
+ assert(hs != NULL);
+
+ err = _dom_element_set_id_attr(element, hs, localname, is_id);
if (err != DOM_NO_ERR)
return err;
- hs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- ns);
- assert(hs != NULL);
-
- err = _dom_element_set_id_attr(element, hs, localname, is_id);
- if (err != DOM_NO_ERR)
- return err;
-
- element->id_ns = ns;
+ element->id_ns = dom_string_ref(namespace);
return DOM_NO_ERR;
}
@@ -910,7 +841,6 @@
{
struct dom_hash_table *hs;
dom_exception err;
- lwc_string *ns;
dom_string *namespace;
dom_string *localname;
@@ -921,19 +851,14 @@
if (err != DOM_NO_ERR)
return err;
- err = _dom_node_get_intern_string(&element->base, namespace, &ns);
+ hs = _dom_hash_get(element->ns_attributes, namespace);
+ assert(hs != NULL);
+
+ err = _dom_element_set_id_attr(element, hs, localname, is_id);
if (err != DOM_NO_ERR)
return err;
- hs = (struct dom_hash_table *) _dom_hash_get(element->ns_attributes,
- ns);
- assert(hs != NULL);
-
- err = _dom_element_set_id_attr(element, hs, localname, is_id);
- if (err != DOM_NO_ERR)
- return err;
-
- element->id_ns = ns;
+ element->id_ns = namespace;
return DOM_NO_ERR;
@@ -1011,17 +936,11 @@
dom_string *namespace, bool *result)
{
struct dom_element *ele = (struct dom_element *) node;
- lwc_string *ns;
dom_string *value;
dom_exception err;
- err = _dom_node_get_intern_string(node, namespace, &ns);
- if (err != DOM_NO_ERR) {
- return err;
- }
if (node->prefix == NULL) {
- lwc_string_isequal(node->namespace, ns, result);
- lwc_string_unref(ns);
+ *result = dom_string_isequal(node->namespace, namespace);
return DOM_NO_ERR;
}
@@ -1032,23 +951,16 @@
return err;
if (has == true) {
- return dom_element_get_attribute(ele, xmlns, &value);
- }
-
- lwc_string *ns2;
- err = _dom_node_get_intern_string(node, value, &ns2);
- if (err != DOM_NO_ERR) {
- return err;
- }
-
- if (ns2 != NULL) {
- lwc_string_isequal(ns2, ns, result);
- lwc_string_unref(ns);
- lwc_string_unref(ns2);
+ err = dom_element_get_attribute(ele, xmlns, &value);
+ if (err != DOM_NO_ERR)
+ return err;
+
+ *result = dom_string_isequal(value, namespace);
+
dom_string_unref(value);
+
return DOM_NO_ERR;
}
-
return dom_node_is_default_namespace(node->parent, namespace, result);
}
@@ -1064,25 +976,17 @@
dom_exception _dom_element_lookup_namespace(dom_node_internal *node,
dom_string *prefix, dom_string **result)
{
- lwc_string *pf;
dom_exception err;
- err = _dom_node_get_intern_string(node, prefix, &pf);
- if (err != DOM_NO_ERR)
- return err;
-
- /* To some extent, directly compare the two lwc_string pointer
- * is better */
- if (node->namespace != NULL && node->prefix == pf) {
- assert(node->owner != NULL);
- return _dom_document_create_string_from_lwcstring(node->owner,
- pf, result);
+ if (node->namespace != NULL &&
+ dom_string_isequal(node->prefix, prefix)) {
+ *result = dom_string_ref(node->namespace);
+ return DOM_NO_ERR;
}
bool has;
dom_string *xmlns = _dom_namespace_get_xmlns_prefix();
- err = dom_element_has_attribute_ns(node,
- dom_namespaces[DOM_NAMESPACE_XMLNS], prefix, &has);
+ err = dom_element_has_attribute_ns(node, xmlns, prefix, &has);
if (err != DOM_NO_ERR)
return err;
@@ -1147,26 +1051,7 @@
/* The destroy virtual function of dom_element */
void __dom_element_destroy(struct dom_node_internal *node)
{
- struct dom_document *doc = dom_node_get_owner(node);
-
- _dom_element_destroy(doc, (struct dom_element *) node);
-}
-
-/* The memory allocator of this class */
-dom_exception _dom_element_alloc(dom_document *doc, struct dom_node_internal *n,
- struct dom_node_internal **ret)
-{
- dom_element *e;
- UNUSED(n);
-
- e = _dom_document_alloc(doc, NULL, sizeof(struct dom_element));
- if (e == NULL)
- return DOM_NO_MEM_ERR;
-
- *ret = (dom_node_internal *) e;
- dom_node_set_owner(*ret, doc);
-
- return DOM_NO_ERR;
+ _dom_element_destroy((struct dom_element *) node);
}
/* TODO: How to deal with default attribue:
@@ -1177,45 +1062,42 @@
* are all specified. For the methods like importNode and adoptNode,
* this will make _dom_element_copy can be used in them.
*/
-dom_exception _dom_element_copy(struct dom_node_internal *new,
- struct dom_node_internal *old)
-{
- dom_element *ne = (dom_element *) new;
- dom_element *oe = (dom_element *) old;
- dom_document *od, *nd;
+dom_exception _dom_element_copy(dom_node_internal *old,
+ dom_node_internal **copy)
+{
+ dom_element *olde = (dom_element *) old;
+ dom_element *e;
struct dom_hash_table *ht;
dom_exception err;
-
- err = _dom_node_copy(new, old);
- if (err != DOM_NO_ERR)
- return err;
- od = dom_node_get_owner(old);
- nd = dom_node_get_owner(new);
- assert(od != NULL);
- assert(nd != NULL);
-
- dom_alloc alloc;
- void *pw;
- _dom_document_get_allocator(nd, &alloc, &pw);
-
+ e = malloc(sizeof(dom_element));
+ if (e == NULL)
+ return DOM_NO_MEM_ERR;
+
+ err = dom_node_copy_internal(old, e);
+ if (err != DOM_NO_ERR) {
+ free(e);
+ return err;
+ }
+
/* Copy the hash tables */
- ht = _dom_hash_clone(oe->attributes, alloc, pw, _key, NULL,
- _value, nd);
+ ht = _dom_hash_clone(olde->attributes, _key, NULL, _value, NULL);
if (ht == NULL)
return DOM_NO_MEM_ERR;
- ne->attributes = ht;
-
- ht = _dom_hash_clone(oe->ns_attributes, alloc, pw, _key, NULL,
- _nsattributes, nd);
+ e->attributes = ht;
+
+ ht = _dom_hash_clone(olde->ns_attributes, _key, NULL,
+ _nsattributes, NULL);
if (ht == NULL)
return DOM_NO_MEM_ERR;
- ne->ns_attributes = ht;
-
- ne->id_ns = NULL;
- ne->id_name = NULL;
+ e->ns_attributes = ht;
+
+ e->id_ns = NULL;
+ e->id_name = NULL;
/* TODO: deal with dom_type_info, it get no definition ! */
+
+ *copy = (dom_node_internal *) e;
return DOM_NO_ERR;
}
@@ -1241,14 +1123,10 @@
{
void *a;
dom_exception err = DOM_NO_ERR;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1274,8 +1152,6 @@
dom_string *value)
{
void *a;
- dom_exception err;
- lwc_string *str;
bool added;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1286,12 +1162,7 @@
if (_dom_node_readonly(e))
return DOM_NO_MODIFICATION_ALLOWED_ERR;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
if (a != NULL) {
/* Found an existing attribute, so replace its value */
@@ -1327,7 +1198,7 @@
dom_exception err;
struct dom_attr *attr;
- err = _dom_attr_create(e->owner, str, NULL, NULL, true, &attr);
+ err = _dom_attr_create(e->owner, name, NULL, NULL, true, &attr);
if (err != DOM_NO_ERR)
return err;
@@ -1364,7 +1235,7 @@
return err;
}
- added = _dom_hash_add(hs, str, attr, false);
+ added = _dom_hash_add(hs, name, attr, false);
if (added == false) {
/* If we failed at this step, there must be no memory */
dom_node_set_parent(attr, NULL);
@@ -1398,19 +1269,13 @@
{
void *a;
dom_exception err;
- lwc_string *str;
dom_node_internal *e = (dom_node_internal *) element;
/* Ensure element can be written to */
if (_dom_node_readonly(e))
return DOM_NO_MODIFICATION_ALLOWED_ERR;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = (dom_node_internal *) _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
/* Detach attr node from list */
if (a != NULL) {
@@ -1425,7 +1290,7 @@
return err;
/* Delete the attribute node */
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
/* Claim a reference for later event dispatch */
dom_node_ref(a);
@@ -1479,15 +1344,10 @@
struct dom_attr **result)
{
void *a;
- dom_exception err;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1522,7 +1382,6 @@
struct dom_attr **result)
{
dom_exception err;
- lwc_string *str = NULL;
dom_string *name = NULL;
bool added;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1546,12 +1405,7 @@
if (err != DOM_NO_ERR)
return err;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
*result = NULL;
if (a != NULL) {
@@ -1564,11 +1418,10 @@
DOM_MUTATION_REMOVAL, &success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
dom_node_ref(a);
*result = (dom_attr *) a;
dom_node_set_parent(a, NULL);
@@ -1584,7 +1437,6 @@
if (err != DOM_NO_ERR && err != DOM_NOT_SUPPORTED_ERR) {
dom_node_unref(a);
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
err = _dom_dispatch_attr_modified_event(doc, e, old, NULL,
@@ -1593,7 +1445,6 @@
dom_string_unref(old);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
@@ -1602,15 +1453,13 @@
(dom_event_target *) e, &success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
}
- added = _dom_hash_add(hs, str, attr, false);
+ added = _dom_hash_add(hs, name, attr, false);
if (added == false) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
/* If we failed at this step, there must be no memory */
return DOM_NO_MEM_ERR;
}
@@ -1633,7 +1482,6 @@
/* Cleanup */
dom_string_unref(new);
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
if (err != DOM_NO_ERR) {
return err;
}
@@ -1674,7 +1522,6 @@
{
void *a;
dom_exception err;
- lwc_string *str;
dom_string *name;
dom_node_internal *e = (dom_node_internal *) element;
@@ -1686,18 +1533,12 @@
if (err != DOM_NO_ERR)
return err;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+ a = _dom_hash_get(hs, name);
/** \todo defaulted attribute handling */
if (a == NULL || a != (void *) attr) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return DOM_NOT_FOUND_ERR;
}
@@ -1709,17 +1550,15 @@
&success);
if (err != DOM_NO_ERR) {
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
return err;
}
/* Delete the attribute node */
- _dom_hash_del(hs, str);
+ _dom_hash_del(hs, name);
dom_node_ref(a);
- /* Now, cleaup the dom_string and lwc_string */
+ /* Now, cleaup the dom_string */
dom_string_unref(name);
- _dom_node_unref_intern_string(&element->base, str);
/* Dispatch a DOMAttrModified event */
dom_string *old = NULL;
@@ -1771,15 +1610,10 @@
bool *result)
{
void *a;
- dom_exception err;
- lwc_string *str;
-
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- a = _dom_hash_get(hs, str);
+
+ UNUSED(element);
+
+ a = _dom_hash_get(hs, name);
/* Fill in value */
if (a == NULL) {
@@ -1804,16 +1638,9 @@
struct dom_hash_table *hs, dom_string *name, bool is_id)
{
dom_attr *attr;
- lwc_string *str;
- dom_exception err;
struct dom_hash_table *oh;
- /* Looking for name */
- err = _dom_node_get_intern_string(&element->base, name, &str);
- if (err != DOM_NO_ERR)
- return err;
-
- attr = (dom_attr *) _dom_hash_get(hs, str);
+ attr = _dom_hash_get(hs, name);
if (attr == NULL)
return DOM_NOT_FOUND_ERR;
@@ -1821,15 +1648,15 @@
/* Firstly, clear the previous id attribute if there is one */
if (element->id_ns != NULL) {
assert(element->id_name != NULL);
- oh = (struct dom_hash_table *) _dom_hash_get(
- element->ns_attributes, element->id_ns);
+ oh = _dom_hash_get(element->ns_attributes,
+ element->id_ns);
} else {
oh = element->attributes;
}
assert(oh != NULL);
if (element->id_name != NULL) {
- attr = (dom_attr *) _dom_hash_get(oh, element->id_name);
+ attr = _dom_hash_get(oh, element->id_name);
assert(attr != NULL);
_dom_attr_set_isid(attr, false);
}
@@ -1837,7 +1664,7 @@
_dom_attr_set_isid(attr, is_id);
- element->id_name = str;
+ element->id_name = dom_string_ref(name);
return DOM_NO_ERR;
}
@@ -1849,7 +1676,7 @@
* \param id The ID of this element
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_element_get_id(struct dom_element *ele, lwc_string **id)
+dom_exception _dom_element_get_id(struct dom_element *ele, dom_string **id)
{
dom_exception err;
dom_string *ret = NULL;
@@ -1862,32 +1689,13 @@
doc = dom_node_get_owner(ele);
assert(doc != NULL);
- dom_string *namespace, *name;
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_ns, &namespace);
- if (err != DOM_NO_ERR)
- return err;
-
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_name, &name);
+ err = _dom_element_get_attribute_ns(ele, ele->id_ns,
+ ele->id_name, &ret);
if (err != DOM_NO_ERR) {
- dom_string_unref(namespace);
return err;
}
- err = _dom_element_get_attribute_ns(ele, namespace, name, &ret);
- if (err != DOM_NO_ERR) {
- dom_string_unref(namespace);
- dom_string_unref(name);
- return err;
- }
-
- dom_string_unref(namespace);
- dom_string_unref(name);
-
- err = _dom_node_get_intern_string((dom_node_internal *) ele,
- ret, id);
- dom_string_unref(ret);
+ *id = ret;
return err;
}
@@ -1897,37 +1705,24 @@
dom_string *name;
if (ele->id_name != NULL) {
- err = _dom_document_create_string_from_lwcstring(doc,
- ele->id_name, &name);
- if (err != DOM_NO_ERR) {
- return err;
- }
+ name = ele->id_name;
} else {
- lwc_string *id_name = _dom_document_get_id_name(doc);
- if (id_name == NULL) {
+ name = _dom_document_get_id_name(doc);
+
+ if (name == NULL) {
/* No ID attribute at all, just return NULL */
*id = NULL;
return DOM_NO_ERR;
}
- err = _dom_document_create_string_from_lwcstring(doc, id_name,
- &name);
- if (err != DOM_NO_ERR) {
- return err;
- }
}
err = _dom_element_get_attribute(ele, name, &ret);
if (err != DOM_NO_ERR) {
- dom_string_unref(name);
- return err;
- }
-
- dom_string_unref(name);
+ return err;
+ }
if (ret != NULL) {
- err = _dom_node_get_intern_string((dom_node_internal *) ele,
- ret, id);
- dom_string_unref(ret);
+ *id = ret;
} else {
*id = NULL;
}
@@ -2130,40 +1925,26 @@
/*------------------ End of namednodemap functions -----------------------*/
/* The key_func of the hash table, see utils/hashtable.h for details */
-void *_key(void *key, void *key_pw, dom_alloc alloc, void *pw,
- bool clone)
+void *_key(void *key, void *key_pw, bool clone)
{
assert(key != NULL);
UNUSED(key_pw);
- UNUSED(alloc);
- UNUSED(pw);
if (clone == false) {
- lwc_string_unref((lwc_string *) key);
+ dom_string_unref((dom_string *) key);
return NULL;
} else {
- lwc_error err;
- lwc_string *ret;
- const char *data = lwc_string_data((lwc_string *) key);
- size_t len = lwc_string_length((lwc_string *) key);
- err = lwc_intern_string(data, len, &ret);
- if (err != lwc_error_ok)
- return NULL;
-
- return ret;
+ return dom_string_ref((dom_string *) key);
}
}
/* The value_func of the hash table, see utils/hashtable.h for details */
-void *_value(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone)
+void *_value(void *value, void *value_pw, bool clone)
{
assert(value != NULL);
- assert(value_pw != NULL);
-
- UNUSED(alloc);
- UNUSED(pw);
+
+ UNUSED(value_pw);
if (clone == false) {
dom_node_internal *a = (dom_node_internal *) value;
@@ -2174,8 +1955,7 @@
dom_exception err;
dom_node *node;
- err = dom_document_import_node((dom_document *) value_pw, value,
- true, &node);
+ err = dom_node_clone_node(value, true, &node);
if (err != DOM_NO_ERR)
return NULL;
@@ -2184,28 +1964,21 @@
}
/* The value_func of the hash table, see utils/hashtable.h for details */
-void *_nsattributes(void *value, void *value_pw, dom_alloc alloc,
- void *pw, bool clone)
+void *_nsattributes(void *value, void *value_pw, bool clone)
{
assert(value != NULL);
- assert(value_pw != NULL);
-
- UNUSED(alloc);
- UNUSED(pw);
+
+ UNUSED(value_pw);
if (clone == false) {
_dom_hash_destroy((struct dom_hash_table *) value, _key,
- value_pw, _value, value_pw);
+ NULL, _value, NULL);
return NULL;
} else {
- dom_document *doc = (dom_document *) value_pw;
- dom_alloc alloc;
- void *pw;
struct dom_hash_table *ret = NULL;
- _dom_document_get_allocator(doc, &alloc, &pw);
-
- ret = _dom_hash_clone((struct dom_hash_table *) value, alloc,
- pw, _key, NULL, _value, doc);
+
+ ret = _dom_hash_clone((struct dom_hash_table *) value,
+ _key, NULL, _value, NULL);
return ret;
}
Modified: branches/jmb/dom-alloc-purge/src/core/element.h
URL:
http://source.netsurf-browser.org/branches/jmb/dom-alloc-purge/src/core/e...
==============================================================================
--- branches/jmb/dom-alloc-purge/src/core/element.h (original)
+++ branches/jmb/dom-alloc-purge/src/core/element.h Sun May 22 06:17:26 2011
@@ -48,10 +48,9 @@
struct dom_element *el, dom_string *name,
dom_string *namespace, dom_string *prefix);
-void _dom_element_finalise(struct dom_document *doc, struct dom_element *ele);
-
-void _dom_element_destroy(struct dom_document *doc,
- struct dom_element *element);
+void _dom_element_finalise(struct dom_element *ele);
+
+void _dom_element_destroy(struct dom_element *element);
/* The virtual functions of dom_element */