From 21c4cf585294abe80acf3c959dc52537aeaa6f33 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 4 Jul 2012 18:22:18 +0100 Subject: HTMLDocument: Memoise 'title' 'lang' 'dir' and 'class' too --- src/html/html_document.c | 32 +++++++++++++++++++++++++++++--- src/html/html_document.h | 4 ++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/html/html_document.c b/src/html/html_document.c index 80737e6..a18218b 100644 --- a/src/html/html_document.c +++ b/src/html/html_document.c @@ -74,9 +74,31 @@ dom_exception _dom_html_document_initialise(dom_html_document *doc, doc->domain = NULL; doc->url = NULL; doc->cookie = NULL; - - error = dom_string_create_interned((const uint8_t *) "id", SLEN("id"), - &doc->_memo_id); + + doc->_memo_id = doc->_memo_title = doc->_memo_lang = + doc->_memo_dir = doc->_memo_class = NULL; + +#define MEMOISE(attr) \ + error = dom_string_create_interned((const uint8_t *) #attr, \ + SLEN(#attr), &doc->_memo_##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; \ + } + + MEMOISE(id) + MEMOISE(title) + MEMOISE(lang) + MEMOISE(dir) + MEMOISE(class) + return error; } @@ -90,6 +112,10 @@ void _dom_html_document_finalise(dom_html_document *doc) 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); _dom_document_finalise(&doc->base); } diff --git a/src/html/html_document.h b/src/html/html_document.h index e3cd80a..57ec1ec 100644 --- a/src/html/html_document.h +++ b/src/html/html_document.h @@ -26,6 +26,10 @@ struct dom_html_document { /* Cached strings for html objects to use */ dom_string *_memo_id; /**< Memoised 'id' */ + dom_string *_memo_title;/**< Memoised 'title' */ + dom_string *_memo_lang; /**< Memoised 'lang' */ + dom_string *_memo_dir; /**< Memoised 'dir' */ + dom_string *_memo_class;/**< Memoised 'class' */ }; /* Create a HTMLDocument */ -- cgit v1.2.3