summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/document.c98
-rw-r--r--src/core/document.h9
-rw-r--r--src/events/dispatch.c39
3 files changed, 115 insertions, 31 deletions
diff --git a/src/core/document.c b/src/core/document.c
index d668c0e..97d93a6 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -156,6 +156,97 @@ dom_exception _dom_document_initialise(dom_document *doc,
return err;
}
+ err = dom_string_create_interned((const uint8_t *) "DOMNodeInserted",
+ SLEN("DOMNodeInserted"),
+ &doc->_memo_domnodeinserted);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMNodeRemoved",
+ SLEN("DOMNodeRemoved"),
+ &doc->_memo_domnoderemoved);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMNodeInsertedIntoDocument",
+ SLEN("DOMNodeInsertedIntoDocument"),
+ &doc->_memo_domnodeinsertedintodocument);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMNodeRemovedFromDocument",
+ SLEN("DOMNodeRemovedFromDocument"),
+ &doc->_memo_domnoderemovedfromdocument);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domnodeinsertedintodocument);
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMAttrModified",
+ SLEN("DOMAttrModified"),
+ &doc->_memo_domattrmodified);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domnoderemovedfromdocument);
+ dom_string_unref(doc->_memo_domnodeinsertedintodocument);
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMCharacterDataModified",
+ SLEN("DOMCharacterDataModified"),
+ &doc->_memo_domcharacterdatamodified);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domattrmodified);
+ dom_string_unref(doc->_memo_domnoderemovedfromdocument);
+ dom_string_unref(doc->_memo_domnodeinsertedintodocument);
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
+ err = dom_string_create_interned((const uint8_t *) "DOMSubtreeModified",
+ SLEN("DOMSubtreeModified"),
+ &doc->_memo_domsubtreemodified);
+ if (err != DOM_NO_ERR) {
+ dom_string_unref(doc->_memo_domcharacterdatamodified);
+ dom_string_unref(doc->_memo_domattrmodified);
+ dom_string_unref(doc->_memo_domnoderemovedfromdocument);
+ dom_string_unref(doc->_memo_domnodeinsertedintodocument);
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->id_name);
+ dom_string_unref(doc->class_string);
+ return err;
+ }
+
/* We should not pass a NULL when all things hook up */
return _dom_document_event_internal_initialise(doc, &doc->dei, daf);
}
@@ -191,6 +282,13 @@ bool _dom_document_finalise(dom_document *doc)
dom_string_unref(doc->class_string);
dom_string_unref(doc->_memo_empty);
+ dom_string_unref(doc->_memo_domnodeinserted);
+ dom_string_unref(doc->_memo_domnoderemoved);
+ dom_string_unref(doc->_memo_domnodeinsertedintodocument);
+ dom_string_unref(doc->_memo_domnoderemovedfromdocument);
+ dom_string_unref(doc->_memo_domattrmodified);
+ dom_string_unref(doc->_memo_domcharacterdatamodified);
+ dom_string_unref(doc->_memo_domsubtreemodified);
_dom_document_event_internal_finalise(doc, &doc->dei);
diff --git a/src/core/document.h b/src/core/document.h
index 6cf1f91..89635ff 100644
--- a/src/core/document.h
+++ b/src/core/document.h
@@ -59,6 +59,15 @@ struct dom_document {
dom_document_quirks_mode quirks;
/**< Document is in quirks mode */
dom_string *_memo_empty; /**< The string ''. */
+
+ /* Memoised event strings */
+ dom_string *_memo_domnodeinserted; /**< DOMNodeInserted */
+ dom_string *_memo_domnoderemoved; /**< DOMNodeRemoved */
+ dom_string *_memo_domnodeinsertedintodocument; /**< DOMNodeInsertedIntoDocument */
+ dom_string *_memo_domnoderemovedfromdocument; /**< DOMNodeRemovedFromDocument */
+ dom_string *_memo_domattrmodified; /**< DOMAttrModified */
+ dom_string *_memo_domcharacterdatamodified; /**< DOMCharacterDataModified */
+ dom_string *_memo_domsubtreemodified; /**< DOMSubtreeModified */
};
/* Create a DOM document */
diff --git a/src/events/dispatch.c b/src/events/dispatch.c
index 743cddc..8f97614 100644
--- a/src/events/dispatch.c
+++ b/src/events/dispatch.c
@@ -7,6 +7,7 @@
#include <assert.h>
+#include "core/document.h"
#include "events/dispatch.h"
#include "events/mutation_event.h"
@@ -35,15 +36,9 @@ dom_exception __dom_dispatch_node_change_event(dom_document *doc,
return err;
if (change == DOM_MUTATION_ADDITION) {
- err = dom_string_create((const uint8_t *) "DOMNodeInserted",
- SLEN("DOMNodeInserted"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domnodeinserted);
} else if (change == DOM_MUTATION_REMOVAL) {
- err = dom_string_create((const uint8_t *) "DOMNodeRemoval",
- SLEN("DOMNodeRemoved"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domnoderemoved);
} else {
assert("Should never be here" == NULL);
}
@@ -87,18 +82,9 @@ dom_exception __dom_dispatch_node_change_document_event(dom_document *doc,
return err;
if (change == DOM_MUTATION_ADDITION) {
- err = dom_string_create(
- (const uint8_t *)
- "DOMNodeInsertedIntoDocument",
- SLEN("DOMNodeInsertedIntoDocument"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domnodeinsertedintodocument);
} else if (change == DOM_MUTATION_REMOVAL) {
- err = dom_string_create(
- (const uint8_t *) "DOMNodeRemovedFromDocument",
- SLEN("DOMNodeRemovedFromDocument"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domnoderemovedfromdocument);
} else {
assert("Should never be here" == NULL);
}
@@ -146,10 +132,7 @@ dom_exception __dom_dispatch_attr_modified_event(dom_document *doc,
if (err != DOM_NO_ERR)
return err;
- err = dom_string_create((const uint8_t *) "DOMAttrModified",
- SLEN("DOMAttrModified"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domattrmodified);
/* Initialise the event with corresponding parameters */
err = dom_mutation_event_init(evt, type, true, false, related,
@@ -193,10 +176,7 @@ dom_exception __dom_dispatch_characterdata_modified_event(
if (err != DOM_NO_ERR)
return err;
- err = dom_string_create((const uint8_t *) "DOMCharacterDataModified",
- SLEN("DOMCharacterDataModified"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domcharacterdatamodified);
err = dom_mutation_event_init(evt, type, true, false, et, prev,
new, NULL, DOM_MUTATION_MODIFICATION);
@@ -232,10 +212,7 @@ dom_exception __dom_dispatch_subtree_modified_event(dom_document *doc,
if (err != DOM_NO_ERR)
return err;
- err = dom_string_create((const uint8_t *) "DOMSubtreeModified",
- SLEN("DOMSubtreeModified"), &type);
- if (err != DOM_NO_ERR)
- goto cleanup;
+ type = dom_string_ref(doc->_memo_domsubtreemodified);
err = dom_mutation_event_init(evt, type, true, false, et, NULL,
NULL, NULL, DOM_MUTATION_MODIFICATION);