Gitweb links:
...log
http://git.netsurf-browser.org/libhubbub.git/shortlog/c4039d355598c9fabbdcc7ef5a663571ef40211d
...commit
http://git.netsurf-browser.org/libhubbub.git/commit/c4039d355598c9fabbdcc7ef5a663571ef40211d
...tree
http://git.netsurf-browser.org/libhubbub.git/tree/c4039d355598c9fabbdcc7ef5a663571ef40211d
The branch, master has been updated
via c4039d355598c9fabbdcc7ef5a663571ef40211d (commit)
via 4de031adb16019295d67fe02e515f9982b32a74b (commit)
via 6c69e82879901a3a8f5eb19914e7ffc4224d0eca (commit)
via 26a7ff24df8cb52c08bab23cff7a8f5ceb3c4465 (commit)
via c0c4d702b5560c0590d73af4ea055514cab38e4f (commit)
from 243345506ea284242cd2b10844996f37080bde5a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libhubbub.git/commit/?id=c4039d355598c9fabbdcc7ef5a663571ef40211d
commit c4039d355598c9fabbdcc7ef5a663571ef40211d
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treebuilder: Allow element_type_from_name to be inlined.
Now it is mostly a wrapper for the gperf-generated
hubbub_element_type_lookup.
This reduces total instruction fetch cost from
4,523,112,517 to 4,511,919,445.
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
index 08f58de..a8e33d9 100644
--- a/src/treebuilder/element-type.h
+++ b/src/treebuilder/element-type.h
@@ -9,6 +9,7 @@
#define hubbub_treebuilder_element_type_h_
#include "treebuilder/treebuilder.h"
+#include "utils/utils.h"
typedef enum
{
@@ -41,9 +42,34 @@ struct element_type_map {
element_type type;
};
+/* Generated by gperf */
const struct element_type_map *hubbub_element_type_lookup(
register const char *str,
register size_t len);
+/**
+ * Convert an element name into an element type
+ *
+ * \param treebuilder The treebuilder instance
+ * \param tag_name The tag name to consider
+ * \return The corresponding element type
+ */
+static inline element_type element_type_from_name(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_string *tag_name)
+{
+ const struct element_type_map *value;
+
+ UNUSED(treebuilder);
+
+ value = hubbub_element_type_lookup((const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
+ }
+
+ return value->type;
+}
+
#endif
diff --git a/src/treebuilder/internal.h b/src/treebuilder/internal.h
index d9e1a00..debc33e 100644
--- a/src/treebuilder/internal.h
+++ b/src/treebuilder/internal.h
@@ -128,9 +128,6 @@ hubbub_error append_text(hubbub_treebuilder *treebuilder,
const hubbub_string *string);
hubbub_error complete_script(hubbub_treebuilder *treebuilder);
-element_type element_type_from_name(hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name);
-
bool is_special_element(element_type type);
bool is_scoping_element(element_type type);
bool is_formatting_element(element_type type);
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index d2a186d..2d2d047 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -915,29 +915,6 @@ hubbub_error append_text(hubbub_treebuilder *treebuilder,
}
/**
- * Convert an element name into an element type
- *
- * \param treebuilder The treebuilder instance
- * \param tag_name The tag name to consider
- * \return The corresponding element type
- */
-element_type element_type_from_name(hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name)
-{
- const struct element_type_map *value;
-
- UNUSED(treebuilder);
-
- value = hubbub_element_type_lookup((const char *)tag_name->ptr,
- tag_name->len);
- if (value == NULL) {
- return UNKNOWN;
- }
-
- return value->type;
-}
-
-/**
* Determine if a node is a special element
*
* \param type Node type to consider
commitdiff
http://git.netsurf-browser.org/libhubbub.git/commit/?id=4de031adb16019295d67fe02e515f9982b32a74b
commit 4de031adb16019295d67fe02e515f9982b32a74b
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Treebuilder: Massively optimise element type from name with gperf.
Loading the html5 single page spec:
* We were spending 10.81% of total runtime in
element_type_from_name. Now it takes 0.66%
of total runtime.
* Total instruction fetch cost is reduced from
5,660,475,511 to 4,523,112,517.
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index 31feae1..ce00a4c 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,6 +6,12 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c
+ generic_rcdata.c element-type.c
+
+$(DIR)element-type.c: $(DIR)element-type.gperf
+ $(VQ)$(ECHO) " GPERF: $<"
+ $(Q)gperf --output-file=$@ $<
+
+CLEAN_ITEMS := $(DIR)element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/element-type.gperf
b/src/treebuilder/element-type.gperf
new file mode 100644
index 0000000..d4f2aa2
--- /dev/null
+++ b/src/treebuilder/element-type.gperf
@@ -0,0 +1,131 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <[email protected]>
+ */
+
+%language=ANSI-C
+%compare-strncmp
+%readonly-tables
+%ignore-case
+%struct-type
+%switch=1
+%define hash-function-name hubbub_element_type_hash
+%define lookup-function-name hubbub_element_type_lookup
+
+%{
+#include <string.h>
+
+#include "treebuilder/element-type.h"
+
+%}
+
+struct element_type_map;
+%%
+a, A
+address, ADDRESS
+annotation-xml, ANNOTATION_XML
+applet, APPLET
+area, AREA
+article, ARTICLE
+aside, ASIDE
+b, B
+base, BASE
+basefont, BASEFONT
+bgsound, BGSOUND
+big, BIG
+blockquote, BLOCKQUOTE
+body, BODY
+br, BR
+button, BUTTON
+caption, CAPTION
+center, CENTER
+col, COL
+colgroup, COLGROUP
+command, COMMAND
+dd, DD
+desc, DESC
+details, DETAILS
+dialog, DIALOG
+dir, DIR
+div, DIV
+dl, DL
+dt, DT
+em, EM
+embed, EMBED
+fieldset, FIELDSET
+figcaption, FIGCAPTION
+figure, FIGURE
+font, FONT
+footer, FOOTER
+foreignobject, FOREIGNOBJECT
+form, FORM
+frame, FRAME
+frameset, FRAMESET
+h1, H1
+h2, H2
+h3, H3
+h4, H4
+h5, H5
+h6, H6
+head, HEAD
+hr, HR
+html, HTML
+i, I
+iframe, IFRAME
+image, IMAGE
+img, IMG
+input, INPUT
+isindex, ISINDEX
+li, LI
+link, LINK
+listing, LISTING
+malignmark, MALIGNMARK
+marquee, MARQUEE
+math, MATH
+menu, MENU
+meta, META
+mglyph, MGLYPH
+mi, MI
+mn, MN
+mo, MO
+ms, MS
+mtext, MTEXT
+nobr, NOBR
+noembed, NOEMBED
+noframes, NOFRAMES
+noscript, NOSCRIPT
+object, OBJECT
+ol, OL
+optgroup, OPTGROUP
+option, OPTION
+output, OUTPUT
+p, P
+param, PARAM
+plaintext, PLAINTEXT
+pre, PRE
+s, S
+script, SCRIPT
+select, SELECT
+small, SMALL
+spacer, SPACER
+strike, STRIKE
+strong, STRONG
+style, STYLE
+summary, SUMMARY
+svg, SVG
+table, TABLE
+tbody, TBODY
+td, TD
+textarea, TEXTAREA
+tfoot, TFOOT
+th, TH
+thead, THEAD
+title, TITLE
+tr, TR
+tt, TT
+u, U
+ul, UL
+wbr, WBR
+xmp, XMP
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
new file mode 100644
index 0000000..08f58de
--- /dev/null
+++ b/src/treebuilder/element-type.h
@@ -0,0 +1,49 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <[email protected]>
+ */
+
+#ifndef hubbub_treebuilder_element_type_h_
+#define hubbub_treebuilder_element_type_h_
+
+#include "treebuilder/treebuilder.h"
+
+typedef enum
+{
+/* Special */
+ ADDRESS, AREA, ARTICLE, ASIDE, BASE, BASEFONT, BGSOUND, BLOCKQUOTE,
+ BODY, BR, CENTER, COL, COLGROUP, COMMAND, DATAGRID, DD, DETAILS,
+ DIALOG, DIR, DIV, DL, DT, EMBED, FIELDSET, FIGCAPTION, FIGURE, FOOTER,
+ FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HR, IFRAME,
+ IMAGE, IMG, INPUT, ISINDEX, LI, LINK, LISTING, MAIN, MENU, META, NAV,
+ NOEMBED, NOFRAMES, NOSCRIPT, OL, OPTGROUP, OPTION, P, PARAM, PLAINTEXT,
+ PRE, SCRIPT, SECTION, SELECT, SPACER, STYLE, SUMMARY, TBODY, TEXTAREA,
+ TFOOT, THEAD, TITLE, TR, UL, WBR,
+/* Scoping */
+ APPLET, BUTTON, CAPTION, HTML, MARQUEE, OBJECT, TABLE, TD, TH,
+/* Formatting */
+ A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
+/* Phrasing */
+ /**< \todo Enumerate phrasing elements */
+ LABEL, OUTPUT, RP, RT, RUBY, SPAN, SUB, SUP, VAR, XMP,
+/* MathML */
+ MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML,
+/* SVG */
+ SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */
+ DESC,
+ UNKNOWN
+} element_type;
+
+struct element_type_map {
+ const char *name;
+ element_type type;
+};
+
+const struct element_type_map *hubbub_element_type_lookup(
+ register const char *str,
+ register size_t len);
+
+#endif
+
diff --git a/src/treebuilder/internal.h b/src/treebuilder/internal.h
index 3c112c9..d9e1a00 100644
--- a/src/treebuilder/internal.h
+++ b/src/treebuilder/internal.h
@@ -9,32 +9,7 @@
#define hubbub_treebuilder_internal_h_
#include "treebuilder/treebuilder.h"
-
-typedef enum
-{
-/* Special */
- ADDRESS, AREA, ARTICLE, ASIDE, BASE, BASEFONT, BGSOUND, BLOCKQUOTE,
- BODY, BR, CENTER, COL, COLGROUP, COMMAND, DATAGRID, DD, DETAILS,
- DIALOG, DIR, DIV, DL, DT, EMBED, FIELDSET, FIGCAPTION, FIGURE, FOOTER,
- FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HR, IFRAME,
- IMAGE, IMG, INPUT, ISINDEX, LI, LINK, LISTING, MAIN, MENU, META, NAV,
- NOEMBED, NOFRAMES, NOSCRIPT, OL, OPTGROUP, OPTION, P, PARAM, PLAINTEXT,
- PRE, SCRIPT, SECTION, SELECT, SPACER, STYLE, SUMMARY, TBODY, TEXTAREA,
- TFOOT, THEAD, TITLE, TR, UL, WBR,
-/* Scoping */
- APPLET, BUTTON, CAPTION, HTML, MARQUEE, OBJECT, TABLE, TD, TH,
-/* Formatting */
- A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
-/* Phrasing */
- /**< \todo Enumerate phrasing elements */
- LABEL, OUTPUT, RP, RT, RUBY, SPAN, SUB, SUP, VAR, XMP,
-/* MathML */
- MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML,
-/* SVG */
- SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */
- DESC,
- UNKNOWN
-} element_type;
+#include "treebuilder/element-type.h"
/**
* Item on the element stack
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index b84ca11..d2a186d 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -17,127 +17,6 @@
#include "utils/utils.h"
#include "utils/string.h"
-
-#define S(x) x, SLEN(x)
-
-static const struct {
- const char *name;
- size_t len;
- element_type type;
-} name_type_map[] = {
- { S("address"), ADDRESS },
- { S("area"), AREA },
- { S("article"), ARTICLE },
- { S("aside"), ASIDE },
- { S("base"), BASE },
- { S("basefont"), BASEFONT },
- { S("bgsound"), BGSOUND },
- { S("blockquote"), BLOCKQUOTE },
- { S("body"), BODY },
- { S("br"), BR },
- { S("center"), CENTER },
- { S("col"), COL },
- { S("colgroup"), COLGROUP },
- { S("command"), COMMAND },
- { S("dd"), DD },
- { S("details"), DETAILS },
- { S("dialog"), DIALOG },
- { S("dir"), DIR },
- { S("div"), DIV },
- { S("dl"), DL },
- { S("dt"), DT },
- { S("embed"), EMBED },
- { S("fieldset"), FIELDSET },
- { S("figcaption"), FIGCAPTION },
- { S("figure"), FIGURE },
- { S("footer"), FOOTER },
- { S("form"), FORM },
- { S("frame"), FRAME },
- { S("frameset"), FRAMESET },
- { S("h1"), H1 },
- { S("h2"), H2 },
- { S("h3"), H3 },
- { S("h4"), H4 },
- { S("h5"), H5 },
- { S("h6"), H6 },
- { S("head"), HEAD },
- { S("hr"), HR },
- { S("iframe"), IFRAME },
- { S("image"), IMAGE },
- { S("img"), IMG },
- { S("input"), INPUT },
- { S("isindex"), ISINDEX },
- { S("li"), LI },
- { S("link"), LINK },
- { S("listing"), LISTING },
- { S("menu"), MENU },
- { S("meta"), META },
- { S("noembed"), NOEMBED },
- { S("noframes"), NOFRAMES },
- { S("noscript"), NOSCRIPT },
- { S("ol"), OL },
- { S("optgroup"), OPTGROUP },
- { S("option"), OPTION },
- { S("output"), OUTPUT },
- { S("p"), P },
- { S("param"), PARAM },
- { S("plaintext"), PLAINTEXT },
- { S("pre"), PRE },
- { S("script"), SCRIPT },
- { S("select"), SELECT },
- { S("spacer"), SPACER },
- { S("style"), STYLE },
- { S("summary"), SUMMARY },
- { S("tbody"), TBODY },
- { S("textarea"), TEXTAREA },
- { S("tfoot"), TFOOT },
- { S("thead"), THEAD },
- { S("title"), TITLE },
- { S("tr"), TR },
- { S("ul"), UL },
- { S("wbr"), WBR },
-
- { S("applet"), APPLET },
- { S("button"), BUTTON },
- { S("caption"), CAPTION },
- { S("html"), HTML },
- { S("marquee"), MARQUEE },
- { S("object"), OBJECT },
- { S("table"), TABLE },
- { S("td"), TD },
- { S("th"), TH },
-
- { S("a"), A },
- { S("b"), B },
- { S("big"), BIG },
- { S("em"), EM },
- { S("font"), FONT },
- { S("i"), I },
- { S("nobr"), NOBR },
- { S("s"), S },
- { S("small"), SMALL },
- { S("strike"), STRIKE },
- { S("strong"), STRONG },
- { S("tt"), TT },
- { S("u"), U },
-
- { S("xmp"), XMP },
-
- { S("math"), MATH },
- { S("mglyph"), MGLYPH },
- { S("malignmark"), MALIGNMARK },
- { S("mi"), MI },
- { S("mo"), MO },
- { S("mn"), MN },
- { S("ms"), MS },
- { S("mtext"), MTEXT },
- { S("annotation-xml"), ANNOTATION_XML },
-
- { S("svg"), SVG },
- { S("desc"), DESC },
- { S("foreignobject"), FOREIGNOBJECT },
-};
-
static bool is_form_associated(element_type type);
/**
@@ -1045,24 +924,17 @@ hubbub_error append_text(hubbub_treebuilder *treebuilder,
element_type element_type_from_name(hubbub_treebuilder *treebuilder,
const hubbub_string *tag_name)
{
- const uint8_t *name = tag_name->ptr;
- size_t len = tag_name->len;
- uint32_t i;
+ const struct element_type_map *value;
UNUSED(treebuilder);
- /** \todo optimise this */
-
- for (i = 0; i < N_ELEMENTS(name_type_map); i++) {
- if (name_type_map[i].len != len)
- continue;
-
- if (strncasecmp(name_type_map[i].name,
- (const char *) name, len) == 0)
- return name_type_map[i].type;
+ value = hubbub_element_type_lookup((const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
}
- return UNKNOWN;
+ return value->type;
}
/**
commitdiff
http://git.netsurf-browser.org/libhubbub.git/commit/?id=6c69e82879901a3a8f5eb19914e7ffc4224d0eca
commit 6c69e82879901a3a8f5eb19914e7ffc4224d0eca
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Perf tester: Optimise tree node data structure with last child pointer.
For loading the html5 single page spec:
* This reduces append_child callback self time from 21% to 0.6% of
total runtime.
* Total instruction fetch cost is reduced from 7,085,287,214 to
5,652,755,136.
This makes it more useful for observing where hubbub itself is slow,
rather than the tester's simple treebuilder implementation.
diff --git a/perf/hubbub.c b/perf/hubbub.c
index c945fe6..53d17c7 100644
--- a/perf/hubbub.c
+++ b/perf/hubbub.c
@@ -50,7 +50,8 @@ struct node_t {
node_t *next;
node_t *prev;
- node_t *child;
+ node_t *child_first;
+ node_t *child_last;
node_t *parent;
};
@@ -276,26 +277,25 @@ hubbub_error append_child(void *ctx, void *parent, void
*child, void **result)
tchild->next = tchild->prev = NULL;
*result = child;
-
if (parent == (void *)1) {
if (Document) {
insert = Document;
+ while (insert->next != NULL) {
+ insert = insert->next;
+ }
} else {
Document = tchild;
}
} else {
- if (tparent->child == NULL) {
- tparent->child = tchild;
+ if (tparent->child_first == NULL) {
+ tparent->child_first = tchild;
+ tparent->child_last = tchild;
} else {
- insert = tparent->child;
+ insert = tparent->child_last;
}
}
if (insert) {
- while (insert->next != NULL) {
- insert = insert->next;
- }
-
if (tchild->type == CHARACTER && insert->type == CHARACTER) {
insert->data.content = realloc(insert->data.content,
strlen(insert->data.content) +
@@ -305,6 +305,10 @@ hubbub_error append_child(void *ctx, void *parent, void
*child, void **result)
} else {
insert->next = tchild;
tchild->prev = insert;
+ if (insert->parent != NULL &&
+ insert->parent != (void *)1) {
+ insert->parent->child_last = insert;
+ }
}
}
@@ -341,7 +345,7 @@ hubbub_error insert_before(void *ctx, void *parent, void
*child, void *ref_child
if (tchild->prev)
tchild->prev->next = tchild;
else
- tparent->child = tchild;
+ tparent->child_first = tchild;
*result = child;
}
@@ -356,11 +360,16 @@ hubbub_error remove_child(void *ctx, void *parent, void
*child, void **result)
UNUSED(ctx);
- assert(tparent->child);
+ assert(tparent->child_last);
+ assert(tparent->child_first);
assert(tchild->parent == tparent);
- if (tchild->parent->child == tchild) {
- tchild->parent->child = tchild->next;
+ if (tchild->parent->child_first == tchild) {
+ tchild->parent->child_first = tchild->next;
+ }
+
+ if (tchild->parent->child_last == tchild) {
+ tchild->parent->child_last = tchild->prev;
}
if (tchild->prev)
@@ -387,10 +396,6 @@ hubbub_error clone_node(void *ctx, void *node, bool deep,
void **result)
*new_node = *old_node;
*result = new_node;
- new_node->child = new_node->parent =
- new_node->next = new_node->prev =
- NULL;
-
if (deep == false)
return HUBBUB_OK;
@@ -401,15 +406,22 @@ hubbub_error clone_node(void *ctx, void *node, bool deep,
void **result)
new_node->next = n;
new_node->next->prev = new_node;
+
+ new_node->parent = old_node->parent;
+ if (new_node->parent != NULL && new_node->parent != (void *)1) {
+ new_node->parent->child_last = new_node;
+ }
}
- if (old_node->child) {
+ if (old_node->child_first) {
void *n;
- clone_node(ctx, old_node->child, true, &n);
+ clone_node(ctx, old_node->child_first, true, &n);
- new_node->child = n;
- new_node->child->parent = new_node;
+ if (new_node)
+ new_node->child_last = n;
+ new_node->child_first = n;
+ new_node->child_first->parent = new_node;
}
return HUBBUB_OK;
@@ -422,30 +434,30 @@ hubbub_error reparent_children(void *ctx, void *node,
void *new_parent)
node_t *old_parent = node;
node_t *insert;
- node_t *kids;
+ node_t *kids_first;
+ node_t *kids_last;
UNUSED(ctx);
- kids = old_parent->child;
- if (!kids) return HUBBUB_OK;
+ kids_first = old_parent->child_first;
+ kids_last = old_parent->child_last;
+ if (!kids_first) return HUBBUB_OK;
- old_parent->child = NULL;
+ old_parent->child_first = NULL;
+ old_parent->child_last = NULL;
- insert = parent->child;
+ insert = parent->child_last;
if (!insert) {
- parent->child = kids;
+ parent->child_first = kids_first;
} else {
- while (insert->next != NULL) {
- insert = insert->next;
- }
-
- insert->next = kids;
- kids->prev = insert;
+ insert->next = kids_first;
+ kids_first->prev = insert;
}
+ parent->child_last = kids_last;
- while (kids) {
- kids->parent = parent;
- kids = kids->next;
+ while (kids_first) {
+ kids_first->parent = parent;
+ kids_first = kids_first->next;
}
return HUBBUB_OK;
@@ -465,7 +477,7 @@ hubbub_error has_children(void *ctx, void *node, bool
*result)
{
UNUSED(ctx);
- *result = ((node_t *)node)->child ? true : false;
+ *result = ((node_t *)node)->child_first ? true : false;
return HUBBUB_OK;
}
commitdiff
http://git.netsurf-browser.org/libhubbub.git/commit/?id=26a7ff24df8cb52c08bab23cff7a8f5ceb3c4465
commit 26a7ff24df8cb52c08bab23cff7a8f5ceb3c4465
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Tests: Squash comparison of signed vs unsigned warnings.
diff --git a/test/tokeniser2.c b/test/tokeniser2.c
index 79d84ca..f38f7ab 100644
--- a/test/tokeniser2.c
+++ b/test/tokeniser2.c
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
tests = json_object_get_array((struct json_object *)
(json_object_get_object(json)->head)->v);
- for (i = 0; i < array_list_length(tests); i++) {
+ for (i = 0; i < (int)array_list_length(tests); i++) {
/* Get test */
struct json_object *test =
(struct json_object *) array_list_get_idx(tests, i);
@@ -216,7 +216,7 @@ hubbub_error token_handler(const hubbub_token *token, void
*pw)
struct json_object *obj = NULL;
struct array_list *items;
- for (; ctx->output_index < array_list_length(ctx->output);
+ for (; ctx->output_index < (int)array_list_length(ctx->output);
ctx->output_index++) {
/* Get object for index */
obj = (struct json_object *)
@@ -236,11 +236,11 @@ hubbub_error token_handler(const hubbub_token *token,
void *pw)
* produced more tokens than expected. We allow for the generation
* of a terminating EOF token, however. */
assert("too many tokens" &&
- (ctx->output_index < array_list_length(ctx->output) ||
+ (ctx->output_index <
(int)array_list_length(ctx->output) ||
token->type == HUBBUB_TOKEN_EOF));
/* Got a terminating EOF -- no error */
- if (ctx->output_index >= array_list_length(ctx->output))
+ if (ctx->output_index >= (int)array_list_length(ctx->output))
return HUBBUB_OK;
/* Now increment the output index so we don't re-expect this token */
diff --git a/test/tokeniser3.c b/test/tokeniser3.c
index 22bda5c..416ff5d 100644
--- a/test/tokeniser3.c
+++ b/test/tokeniser3.c
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
tests = json_object_get_array((struct json_object *)
(json_object_get_object(json)->head)->v);
- for (i = 0; i < array_list_length(tests); i++) {
+ for (i = 0; i < (int)array_list_length(tests); i++) {
/* Get test */
struct json_object *test =
(struct json_object *) array_list_get_idx(tests, i);
@@ -221,7 +221,7 @@ hubbub_error token_handler(const hubbub_token *token, void
*pw)
struct json_object *obj = NULL;
struct array_list *items;
- for (; ctx->output_index < array_list_length(ctx->output);
+ for (; ctx->output_index < (int)array_list_length(ctx->output);
ctx->output_index++) {
/* Get object for index */
obj = (struct json_object *)
@@ -241,11 +241,11 @@ hubbub_error token_handler(const hubbub_token *token,
void *pw)
* produced more tokens than expected. We allow for the generation
* of a terminating EOF token, however. */
assert("too many tokens" &&
- (ctx->output_index < array_list_length(ctx->output) ||
+ (ctx->output_index <
(int)array_list_length(ctx->output) ||
token->type == HUBBUB_TOKEN_EOF));
/* Got a terminating EOF -- no error */
- if (ctx->output_index >= array_list_length(ctx->output))
+ if (ctx->output_index >= (int)array_list_length(ctx->output))
return HUBBUB_OK;
/* Now increment the output index so we don't re-expect this token */
commitdiff
http://git.netsurf-browser.org/libhubbub.git/commit/?id=c0c4d702b5560c0590d73af4ea055514cab38e4f
commit c0c4d702b5560c0590d73af4ea055514cab38e4f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Tests: libjson-c does not provide is_error any more.
diff --git a/test/tokeniser2.c b/test/tokeniser2.c
index c8ab9c0..79d84ca 100644
--- a/test/tokeniser2.c
+++ b/test/tokeniser2.c
@@ -48,7 +48,7 @@ int main(int argc, char **argv)
}
json = json_object_from_file(argv[1]);
- assert(!is_error(json));
+ assert(json != NULL);
assert(strcmp((char *) ((json_object_get_object(json)->head)->k),
"tests") == 0);
diff --git a/test/tokeniser3.c b/test/tokeniser3.c
index e33d018..22bda5c 100644
--- a/test/tokeniser3.c
+++ b/test/tokeniser3.c
@@ -46,7 +46,7 @@ int main(int argc, char **argv)
}
json = json_object_from_file(argv[1]);
- assert(!is_error(json));
+ assert(json != NULL);
assert(strcmp((char *) ((json_object_get_object(json)->head)->k),
"tests") == 0);
-----------------------------------------------------------------------
Summary of changes:
perf/hubbub.c | 86 +++++++++++---------
src/treebuilder/Makefile | 8 +-
src/treebuilder/element-type.gperf | 131 +++++++++++++++++++++++++++++++
src/treebuilder/element-type.h | 75 ++++++++++++++++++
src/treebuilder/internal.h | 30 +------
src/treebuilder/treebuilder.c | 151 ------------------------------------
test/tokeniser2.c | 10 +--
test/tokeniser3.c | 10 +--
8 files changed, 273 insertions(+), 228 deletions(-)
create mode 100644 src/treebuilder/element-type.gperf
create mode 100644 src/treebuilder/element-type.h
diff --git a/perf/hubbub.c b/perf/hubbub.c
index c945fe6..53d17c7 100644
--- a/perf/hubbub.c
+++ b/perf/hubbub.c
@@ -50,7 +50,8 @@ struct node_t {
node_t *next;
node_t *prev;
- node_t *child;
+ node_t *child_first;
+ node_t *child_last;
node_t *parent;
};
@@ -276,26 +277,25 @@ hubbub_error append_child(void *ctx, void *parent, void
*child, void **result)
tchild->next = tchild->prev = NULL;
*result = child;
-
if (parent == (void *)1) {
if (Document) {
insert = Document;
+ while (insert->next != NULL) {
+ insert = insert->next;
+ }
} else {
Document = tchild;
}
} else {
- if (tparent->child == NULL) {
- tparent->child = tchild;
+ if (tparent->child_first == NULL) {
+ tparent->child_first = tchild;
+ tparent->child_last = tchild;
} else {
- insert = tparent->child;
+ insert = tparent->child_last;
}
}
if (insert) {
- while (insert->next != NULL) {
- insert = insert->next;
- }
-
if (tchild->type == CHARACTER && insert->type == CHARACTER) {
insert->data.content = realloc(insert->data.content,
strlen(insert->data.content) +
@@ -305,6 +305,10 @@ hubbub_error append_child(void *ctx, void *parent, void
*child, void **result)
} else {
insert->next = tchild;
tchild->prev = insert;
+ if (insert->parent != NULL &&
+ insert->parent != (void *)1) {
+ insert->parent->child_last = insert;
+ }
}
}
@@ -341,7 +345,7 @@ hubbub_error insert_before(void *ctx, void *parent, void
*child, void *ref_child
if (tchild->prev)
tchild->prev->next = tchild;
else
- tparent->child = tchild;
+ tparent->child_first = tchild;
*result = child;
}
@@ -356,11 +360,16 @@ hubbub_error remove_child(void *ctx, void *parent, void
*child, void **result)
UNUSED(ctx);
- assert(tparent->child);
+ assert(tparent->child_last);
+ assert(tparent->child_first);
assert(tchild->parent == tparent);
- if (tchild->parent->child == tchild) {
- tchild->parent->child = tchild->next;
+ if (tchild->parent->child_first == tchild) {
+ tchild->parent->child_first = tchild->next;
+ }
+
+ if (tchild->parent->child_last == tchild) {
+ tchild->parent->child_last = tchild->prev;
}
if (tchild->prev)
@@ -387,10 +396,6 @@ hubbub_error clone_node(void *ctx, void *node, bool deep,
void **result)
*new_node = *old_node;
*result = new_node;
- new_node->child = new_node->parent =
- new_node->next = new_node->prev =
- NULL;
-
if (deep == false)
return HUBBUB_OK;
@@ -401,15 +406,22 @@ hubbub_error clone_node(void *ctx, void *node, bool deep,
void **result)
new_node->next = n;
new_node->next->prev = new_node;
+
+ new_node->parent = old_node->parent;
+ if (new_node->parent != NULL && new_node->parent != (void *)1) {
+ new_node->parent->child_last = new_node;
+ }
}
- if (old_node->child) {
+ if (old_node->child_first) {
void *n;
- clone_node(ctx, old_node->child, true, &n);
+ clone_node(ctx, old_node->child_first, true, &n);
- new_node->child = n;
- new_node->child->parent = new_node;
+ if (new_node)
+ new_node->child_last = n;
+ new_node->child_first = n;
+ new_node->child_first->parent = new_node;
}
return HUBBUB_OK;
@@ -422,30 +434,30 @@ hubbub_error reparent_children(void *ctx, void *node,
void *new_parent)
node_t *old_parent = node;
node_t *insert;
- node_t *kids;
+ node_t *kids_first;
+ node_t *kids_last;
UNUSED(ctx);
- kids = old_parent->child;
- if (!kids) return HUBBUB_OK;
+ kids_first = old_parent->child_first;
+ kids_last = old_parent->child_last;
+ if (!kids_first) return HUBBUB_OK;
- old_parent->child = NULL;
+ old_parent->child_first = NULL;
+ old_parent->child_last = NULL;
- insert = parent->child;
+ insert = parent->child_last;
if (!insert) {
- parent->child = kids;
+ parent->child_first = kids_first;
} else {
- while (insert->next != NULL) {
- insert = insert->next;
- }
-
- insert->next = kids;
- kids->prev = insert;
+ insert->next = kids_first;
+ kids_first->prev = insert;
}
+ parent->child_last = kids_last;
- while (kids) {
- kids->parent = parent;
- kids = kids->next;
+ while (kids_first) {
+ kids_first->parent = parent;
+ kids_first = kids_first->next;
}
return HUBBUB_OK;
@@ -465,7 +477,7 @@ hubbub_error has_children(void *ctx, void *node, bool
*result)
{
UNUSED(ctx);
- *result = ((node_t *)node)->child ? true : false;
+ *result = ((node_t *)node)->child_first ? true : false;
return HUBBUB_OK;
}
diff --git a/src/treebuilder/Makefile b/src/treebuilder/Makefile
index 31feae1..ce00a4c 100644
--- a/src/treebuilder/Makefile
+++ b/src/treebuilder/Makefile
@@ -6,6 +6,12 @@ DIR_SOURCES := treebuilder.c \
in_cell.c in_select.c in_select_in_table.c \
in_foreign_content.c after_body.c in_frameset.c \
after_frameset.c after_after_body.c after_after_frameset.c \
- generic_rcdata.c
+ generic_rcdata.c element-type.c
+
+$(DIR)element-type.c: $(DIR)element-type.gperf
+ $(VQ)$(ECHO) " GPERF: $<"
+ $(Q)gperf --output-file=$@ $<
+
+CLEAN_ITEMS := $(DIR)element-type.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/treebuilder/element-type.gperf
b/src/treebuilder/element-type.gperf
new file mode 100644
index 0000000..d4f2aa2
--- /dev/null
+++ b/src/treebuilder/element-type.gperf
@@ -0,0 +1,131 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2021 Michael Drake <[email protected]>
+ */
+
+%language=ANSI-C
+%compare-strncmp
+%readonly-tables
+%ignore-case
+%struct-type
+%switch=1
+%define hash-function-name hubbub_element_type_hash
+%define lookup-function-name hubbub_element_type_lookup
+
+%{
+#include <string.h>
+
+#include "treebuilder/element-type.h"
+
+%}
+
+struct element_type_map;
+%%
+a, A
+address, ADDRESS
+annotation-xml, ANNOTATION_XML
+applet, APPLET
+area, AREA
+article, ARTICLE
+aside, ASIDE
+b, B
+base, BASE
+basefont, BASEFONT
+bgsound, BGSOUND
+big, BIG
+blockquote, BLOCKQUOTE
+body, BODY
+br, BR
+button, BUTTON
+caption, CAPTION
+center, CENTER
+col, COL
+colgroup, COLGROUP
+command, COMMAND
+dd, DD
+desc, DESC
+details, DETAILS
+dialog, DIALOG
+dir, DIR
+div, DIV
+dl, DL
+dt, DT
+em, EM
+embed, EMBED
+fieldset, FIELDSET
+figcaption, FIGCAPTION
+figure, FIGURE
+font, FONT
+footer, FOOTER
+foreignobject, FOREIGNOBJECT
+form, FORM
+frame, FRAME
+frameset, FRAMESET
+h1, H1
+h2, H2
+h3, H3
+h4, H4
+h5, H5
+h6, H6
+head, HEAD
+hr, HR
+html, HTML
+i, I
+iframe, IFRAME
+image, IMAGE
+img, IMG
+input, INPUT
+isindex, ISINDEX
+li, LI
+link, LINK
+listing, LISTING
+malignmark, MALIGNMARK
+marquee, MARQUEE
+math, MATH
+menu, MENU
+meta, META
+mglyph, MGLYPH
+mi, MI
+mn, MN
+mo, MO
+ms, MS
+mtext, MTEXT
+nobr, NOBR
+noembed, NOEMBED
+noframes, NOFRAMES
+noscript, NOSCRIPT
+object, OBJECT
+ol, OL
+optgroup, OPTGROUP
+option, OPTION
+output, OUTPUT
+p, P
+param, PARAM
+plaintext, PLAINTEXT
+pre, PRE
+s, S
+script, SCRIPT
+select, SELECT
+small, SMALL
+spacer, SPACER
+strike, STRIKE
+strong, STRONG
+style, STYLE
+summary, SUMMARY
+svg, SVG
+table, TABLE
+tbody, TBODY
+td, TD
+textarea, TEXTAREA
+tfoot, TFOOT
+th, TH
+thead, THEAD
+title, TITLE
+tr, TR
+tt, TT
+u, U
+ul, UL
+wbr, WBR
+xmp, XMP
diff --git a/src/treebuilder/element-type.h b/src/treebuilder/element-type.h
new file mode 100644
index 0000000..a8e33d9
--- /dev/null
+++ b/src/treebuilder/element-type.h
@@ -0,0 +1,75 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <[email protected]>
+ */
+
+#ifndef hubbub_treebuilder_element_type_h_
+#define hubbub_treebuilder_element_type_h_
+
+#include "treebuilder/treebuilder.h"
+#include "utils/utils.h"
+
+typedef enum
+{
+/* Special */
+ ADDRESS, AREA, ARTICLE, ASIDE, BASE, BASEFONT, BGSOUND, BLOCKQUOTE,
+ BODY, BR, CENTER, COL, COLGROUP, COMMAND, DATAGRID, DD, DETAILS,
+ DIALOG, DIR, DIV, DL, DT, EMBED, FIELDSET, FIGCAPTION, FIGURE, FOOTER,
+ FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HR, IFRAME,
+ IMAGE, IMG, INPUT, ISINDEX, LI, LINK, LISTING, MAIN, MENU, META, NAV,
+ NOEMBED, NOFRAMES, NOSCRIPT, OL, OPTGROUP, OPTION, P, PARAM, PLAINTEXT,
+ PRE, SCRIPT, SECTION, SELECT, SPACER, STYLE, SUMMARY, TBODY, TEXTAREA,
+ TFOOT, THEAD, TITLE, TR, UL, WBR,
+/* Scoping */
+ APPLET, BUTTON, CAPTION, HTML, MARQUEE, OBJECT, TABLE, TD, TH,
+/* Formatting */
+ A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
+/* Phrasing */
+ /**< \todo Enumerate phrasing elements */
+ LABEL, OUTPUT, RP, RT, RUBY, SPAN, SUB, SUP, VAR, XMP,
+/* MathML */
+ MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML,
+/* SVG */
+ SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */
+ DESC,
+ UNKNOWN
+} element_type;
+
+struct element_type_map {
+ const char *name;
+ element_type type;
+};
+
+/* Generated by gperf */
+const struct element_type_map *hubbub_element_type_lookup(
+ register const char *str,
+ register size_t len);
+
+/**
+ * Convert an element name into an element type
+ *
+ * \param treebuilder The treebuilder instance
+ * \param tag_name The tag name to consider
+ * \return The corresponding element type
+ */
+static inline element_type element_type_from_name(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_string *tag_name)
+{
+ const struct element_type_map *value;
+
+ UNUSED(treebuilder);
+
+ value = hubbub_element_type_lookup((const char *)tag_name->ptr,
+ tag_name->len);
+ if (value == NULL) {
+ return UNKNOWN;
+ }
+
+ return value->type;
+}
+
+#endif
+
diff --git a/src/treebuilder/internal.h b/src/treebuilder/internal.h
index 3c112c9..debc33e 100644
--- a/src/treebuilder/internal.h
+++ b/src/treebuilder/internal.h
@@ -9,32 +9,7 @@
#define hubbub_treebuilder_internal_h_
#include "treebuilder/treebuilder.h"
-
-typedef enum
-{
-/* Special */
- ADDRESS, AREA, ARTICLE, ASIDE, BASE, BASEFONT, BGSOUND, BLOCKQUOTE,
- BODY, BR, CENTER, COL, COLGROUP, COMMAND, DATAGRID, DD, DETAILS,
- DIALOG, DIR, DIV, DL, DT, EMBED, FIELDSET, FIGCAPTION, FIGURE, FOOTER,
- FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HR, IFRAME,
- IMAGE, IMG, INPUT, ISINDEX, LI, LINK, LISTING, MAIN, MENU, META, NAV,
- NOEMBED, NOFRAMES, NOSCRIPT, OL, OPTGROUP, OPTION, P, PARAM, PLAINTEXT,
- PRE, SCRIPT, SECTION, SELECT, SPACER, STYLE, SUMMARY, TBODY, TEXTAREA,
- TFOOT, THEAD, TITLE, TR, UL, WBR,
-/* Scoping */
- APPLET, BUTTON, CAPTION, HTML, MARQUEE, OBJECT, TABLE, TD, TH,
-/* Formatting */
- A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
-/* Phrasing */
- /**< \todo Enumerate phrasing elements */
- LABEL, OUTPUT, RP, RT, RUBY, SPAN, SUB, SUP, VAR, XMP,
-/* MathML */
- MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML,
-/* SVG */
- SVG, FOREIGNOBJECT, /* foreignobject is scoping, but only in SVG ns */
- DESC,
- UNKNOWN
-} element_type;
+#include "treebuilder/element-type.h"
/**
* Item on the element stack
@@ -153,9 +128,6 @@ hubbub_error append_text(hubbub_treebuilder *treebuilder,
const hubbub_string *string);
hubbub_error complete_script(hubbub_treebuilder *treebuilder);
-element_type element_type_from_name(hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name);
-
bool is_special_element(element_type type);
bool is_scoping_element(element_type type);
bool is_formatting_element(element_type type);
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index b84ca11..2d2d047 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -17,127 +17,6 @@
#include "utils/utils.h"
#include "utils/string.h"
-
-#define S(x) x, SLEN(x)
-
-static const struct {
- const char *name;
- size_t len;
- element_type type;
-} name_type_map[] = {
- { S("address"), ADDRESS },
- { S("area"), AREA },
- { S("article"), ARTICLE },
- { S("aside"), ASIDE },
- { S("base"), BASE },
- { S("basefont"), BASEFONT },
- { S("bgsound"), BGSOUND },
- { S("blockquote"), BLOCKQUOTE },
- { S("body"), BODY },
- { S("br"), BR },
- { S("center"), CENTER },
- { S("col"), COL },
- { S("colgroup"), COLGROUP },
- { S("command"), COMMAND },
- { S("dd"), DD },
- { S("details"), DETAILS },
- { S("dialog"), DIALOG },
- { S("dir"), DIR },
- { S("div"), DIV },
- { S("dl"), DL },
- { S("dt"), DT },
- { S("embed"), EMBED },
- { S("fieldset"), FIELDSET },
- { S("figcaption"), FIGCAPTION },
- { S("figure"), FIGURE },
- { S("footer"), FOOTER },
- { S("form"), FORM },
- { S("frame"), FRAME },
- { S("frameset"), FRAMESET },
- { S("h1"), H1 },
- { S("h2"), H2 },
- { S("h3"), H3 },
- { S("h4"), H4 },
- { S("h5"), H5 },
- { S("h6"), H6 },
- { S("head"), HEAD },
- { S("hr"), HR },
- { S("iframe"), IFRAME },
- { S("image"), IMAGE },
- { S("img"), IMG },
- { S("input"), INPUT },
- { S("isindex"), ISINDEX },
- { S("li"), LI },
- { S("link"), LINK },
- { S("listing"), LISTING },
- { S("menu"), MENU },
- { S("meta"), META },
- { S("noembed"), NOEMBED },
- { S("noframes"), NOFRAMES },
- { S("noscript"), NOSCRIPT },
- { S("ol"), OL },
- { S("optgroup"), OPTGROUP },
- { S("option"), OPTION },
- { S("output"), OUTPUT },
- { S("p"), P },
- { S("param"), PARAM },
- { S("plaintext"), PLAINTEXT },
- { S("pre"), PRE },
- { S("script"), SCRIPT },
- { S("select"), SELECT },
- { S("spacer"), SPACER },
- { S("style"), STYLE },
- { S("summary"), SUMMARY },
- { S("tbody"), TBODY },
- { S("textarea"), TEXTAREA },
- { S("tfoot"), TFOOT },
- { S("thead"), THEAD },
- { S("title"), TITLE },
- { S("tr"), TR },
- { S("ul"), UL },
- { S("wbr"), WBR },
-
- { S("applet"), APPLET },
- { S("button"), BUTTON },
- { S("caption"), CAPTION },
- { S("html"), HTML },
- { S("marquee"), MARQUEE },
- { S("object"), OBJECT },
- { S("table"), TABLE },
- { S("td"), TD },
- { S("th"), TH },
-
- { S("a"), A },
- { S("b"), B },
- { S("big"), BIG },
- { S("em"), EM },
- { S("font"), FONT },
- { S("i"), I },
- { S("nobr"), NOBR },
- { S("s"), S },
- { S("small"), SMALL },
- { S("strike"), STRIKE },
- { S("strong"), STRONG },
- { S("tt"), TT },
- { S("u"), U },
-
- { S("xmp"), XMP },
-
- { S("math"), MATH },
- { S("mglyph"), MGLYPH },
- { S("malignmark"), MALIGNMARK },
- { S("mi"), MI },
- { S("mo"), MO },
- { S("mn"), MN },
- { S("ms"), MS },
- { S("mtext"), MTEXT },
- { S("annotation-xml"), ANNOTATION_XML },
-
- { S("svg"), SVG },
- { S("desc"), DESC },
- { S("foreignobject"), FOREIGNOBJECT },
-};
-
static bool is_form_associated(element_type type);
/**
@@ -1036,36 +915,6 @@ hubbub_error append_text(hubbub_treebuilder *treebuilder,
}
/**
- * Convert an element name into an element type
- *
- * \param treebuilder The treebuilder instance
- * \param tag_name The tag name to consider
- * \return The corresponding element type
- */
-element_type element_type_from_name(hubbub_treebuilder *treebuilder,
- const hubbub_string *tag_name)
-{
- const uint8_t *name = tag_name->ptr;
- size_t len = tag_name->len;
- uint32_t i;
-
- UNUSED(treebuilder);
-
- /** \todo optimise this */
-
- for (i = 0; i < N_ELEMENTS(name_type_map); i++) {
- if (name_type_map[i].len != len)
- continue;
-
- if (strncasecmp(name_type_map[i].name,
- (const char *) name, len) == 0)
- return name_type_map[i].type;
- }
-
- return UNKNOWN;
-}
-
-/**
* Determine if a node is a special element
*
* \param type Node type to consider
diff --git a/test/tokeniser2.c b/test/tokeniser2.c
index c8ab9c0..f38f7ab 100644
--- a/test/tokeniser2.c
+++ b/test/tokeniser2.c
@@ -48,7 +48,7 @@ int main(int argc, char **argv)
}
json = json_object_from_file(argv[1]);
- assert(!is_error(json));
+ assert(json != NULL);
assert(strcmp((char *) ((json_object_get_object(json)->head)->k),
"tests") == 0);
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
tests = json_object_get_array((struct json_object *)
(json_object_get_object(json)->head)->v);
- for (i = 0; i < array_list_length(tests); i++) {
+ for (i = 0; i < (int)array_list_length(tests); i++) {
/* Get test */
struct json_object *test =
(struct json_object *) array_list_get_idx(tests, i);
@@ -216,7 +216,7 @@ hubbub_error token_handler(const hubbub_token *token, void
*pw)
struct json_object *obj = NULL;
struct array_list *items;
- for (; ctx->output_index < array_list_length(ctx->output);
+ for (; ctx->output_index < (int)array_list_length(ctx->output);
ctx->output_index++) {
/* Get object for index */
obj = (struct json_object *)
@@ -236,11 +236,11 @@ hubbub_error token_handler(const hubbub_token *token,
void *pw)
* produced more tokens than expected. We allow for the generation
* of a terminating EOF token, however. */
assert("too many tokens" &&
- (ctx->output_index < array_list_length(ctx->output) ||
+ (ctx->output_index <
(int)array_list_length(ctx->output) ||
token->type == HUBBUB_TOKEN_EOF));
/* Got a terminating EOF -- no error */
- if (ctx->output_index >= array_list_length(ctx->output))
+ if (ctx->output_index >= (int)array_list_length(ctx->output))
return HUBBUB_OK;
/* Now increment the output index so we don't re-expect this token */
diff --git a/test/tokeniser3.c b/test/tokeniser3.c
index e33d018..416ff5d 100644
--- a/test/tokeniser3.c
+++ b/test/tokeniser3.c
@@ -46,7 +46,7 @@ int main(int argc, char **argv)
}
json = json_object_from_file(argv[1]);
- assert(!is_error(json));
+ assert(json != NULL);
assert(strcmp((char *) ((json_object_get_object(json)->head)->k),
"tests") == 0);
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
tests = json_object_get_array((struct json_object *)
(json_object_get_object(json)->head)->v);
- for (i = 0; i < array_list_length(tests); i++) {
+ for (i = 0; i < (int)array_list_length(tests); i++) {
/* Get test */
struct json_object *test =
(struct json_object *) array_list_get_idx(tests, i);
@@ -221,7 +221,7 @@ hubbub_error token_handler(const hubbub_token *token, void
*pw)
struct json_object *obj = NULL;
struct array_list *items;
- for (; ctx->output_index < array_list_length(ctx->output);
+ for (; ctx->output_index < (int)array_list_length(ctx->output);
ctx->output_index++) {
/* Get object for index */
obj = (struct json_object *)
@@ -241,11 +241,11 @@ hubbub_error token_handler(const hubbub_token *token,
void *pw)
* produced more tokens than expected. We allow for the generation
* of a terminating EOF token, however. */
assert("too many tokens" &&
- (ctx->output_index < array_list_length(ctx->output) ||
+ (ctx->output_index <
(int)array_list_length(ctx->output) ||
token->type == HUBBUB_TOKEN_EOF));
/* Got a terminating EOF -- no error */
- if (ctx->output_index >= array_list_length(ctx->output))
+ if (ctx->output_index >= (int)array_list_length(ctx->output))
return HUBBUB_OK;
/* Now increment the output index so we don't re-expect this token */
--
HTML5 parser library
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]