aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2015-01-10 16:10:22 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2015-01-10 16:13:25 +0100
commitd548d56d604193e4eebb4ab81c347887763b7d69 (patch)
tree5a7da25cbfe2937089eb6bf4c8b53f0533296357
parentee502421b239bc1c8e74d0578d9615a641b5cc81 (diff)
Optimize S_is_leaf
-rw-r--r--src/iterator.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/iterator.c b/src/iterator.c
index a3ae415..0354eff 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -5,6 +5,16 @@
#include "cmark.h"
#include "iterator.h"
+static const int S_leaf_mask =
+ (1 << CMARK_NODE_HTML) |
+ (1 << CMARK_NODE_HRULE) |
+ (1 << CMARK_NODE_CODE_BLOCK) |
+ (1 << CMARK_NODE_TEXT) |
+ (1 << CMARK_NODE_SOFTBREAK) |
+ (1 << CMARK_NODE_LINEBREAK) |
+ (1 << CMARK_NODE_CODE) |
+ (1 << CMARK_NODE_INLINE_HTML);
+
cmark_iter*
cmark_iter_new(cmark_node *root)
{
@@ -31,21 +41,10 @@ cmark_iter_next(cmark_iter *iter)
return iter->event_type;
}
-int S_is_leaf(cmark_node *node)
+static bool
+S_is_leaf(cmark_node *node)
{
- switch (cmark_node_get_type(node)) {
- case CMARK_NODE_HTML:
- case CMARK_NODE_HRULE:
- case CMARK_NODE_CODE_BLOCK:
- case CMARK_NODE_TEXT:
- case CMARK_NODE_SOFTBREAK:
- case CMARK_NODE_LINEBREAK:
- case CMARK_NODE_CODE:
- case CMARK_NODE_INLINE_HTML:
- return 1;
- default:
- return 0;
- }
+ return (1 << node->type) & S_leaf_mask;
}
void