diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-07 10:56:51 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-07 10:56:51 +0100 |
commit | eec1716bbd8a692aa260c24db57c0465fcb9fb43 (patch) | |
tree | 051286c5c2601533d8b0ec70065c39c10a959968 /src/html/html_document.c | |
parent | 4e99ad2213dba5244f2df0f73d8c32c16f995840 (diff) | |
download | libdom-eec1716bbd8a692aa260c24db57c0465fcb9fb43.tar.gz libdom-eec1716bbd8a692aa260c24db57c0465fcb9fb43.tar.bz2 |
HTML: Make Document memoise more generically and port HTMLElement to that interface
Diffstat (limited to 'src/html/html_document.c')
-rw-r--r-- | src/html/html_document.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/src/html/html_document.c b/src/html/html_document.c index a18218b..e618deb 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -64,6 +64,7 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc, dom_events_default_action_fetcher daf) { dom_exception error; + int sidx; error = _dom_document_initialise(&doc->base, daf); if (error != DOM_NO_ERR) @@ -75,47 +76,55 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc, doc->url = NULL; doc->cookie = NULL; - doc->_memo_id = doc->_memo_title = doc->_memo_lang = - doc->_memo_dir = doc->_memo_class = NULL; + doc->memoised = calloc(sizeof(dom_string *), hds_COUNT); + if (doc->memoised == NULL) { + error = DOM_NO_MEM_ERR; + goto out; + } -#define MEMOISE(attr) \ +#define HTML_DOCUMENT_STRINGS_ACTION(attr) \ error = dom_string_create_interned((const uint8_t *) #attr, \ - SLEN(#attr), &doc->_memo_##attr); \ + SLEN(#attr), &doc->memoised[hds_##attr]); \ if (error != DOM_NO_ERR) { \ - if (doc->_memo_id != NULL) \ - dom_string_unref(doc->_memo_id); \ - if (doc->_memo_title != NULL) \ - dom_string_unref(doc->_memo_title); \ - if (doc->_memo_lang != NULL) \ - dom_string_unref(doc->_memo_lang); \ - if (doc->_memo_dir != NULL) \ - dom_string_unref(doc->_memo_dir); \ - return error; \ + goto out; \ + } + +#include "html_document_strings.h" +#undef HTML_DOCUMENT_STRINGS_ACTION + +out: + if (doc->memoised != NULL && error != DOM_NO_ERR) { + for(sidx = 0; sidx < hds_COUNT; ++sidx) { + if (doc->memoised[sidx] != NULL) { + dom_string_unref(doc->memoised[sidx]); + } + } + free(doc->memoised); + doc->memoised = NULL; } - - MEMOISE(id) - MEMOISE(title) - MEMOISE(lang) - MEMOISE(dir) - MEMOISE(class) - return error; } /* Finalise a HTMLDocument */ void _dom_html_document_finalise(dom_html_document *doc) { + int sidx; + dom_string_unref(doc->cookie); dom_string_unref(doc->url); dom_string_unref(doc->domain); dom_string_unref(doc->referrer); dom_string_unref(doc->title); - dom_string_unref(doc->_memo_id); - dom_string_unref(doc->_memo_title); - dom_string_unref(doc->_memo_lang); - dom_string_unref(doc->_memo_dir); - dom_string_unref(doc->_memo_class); + if (doc->memoised != NULL) { + for(sidx = 0; sidx < hds_COUNT; ++sidx) { + if (doc->memoised[sidx] != NULL) { + dom_string_unref(doc->memoised[sidx]); + } + } + free(doc->memoised); + doc->memoised = NULL; + } _dom_document_finalise(&doc->base); } |