summaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-12-01 10:48:15 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-12-01 10:48:15 +0000
commit960ba431494f4694ef2b813e4c7968c2bbe68748 (patch)
tree98a50201f901ee8e81ac1f8476140b74d08a13dd /src/runtime
parent14a2821fd8fd44af6b12df9236666a9bae95175a (diff)
a small optimization in the PGF parser which gives me ~5% speed up
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/c/pgf/parser.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index b360e0e81..07be86525 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -593,19 +593,10 @@ cmp_item_production_idx_entry(GuOrder* self, const void* a, const void* b)
static GuOrder
pgf_production_idx_entry_order[1] = { { cmp_item_production_idx_entry } };
-static PgfItemContss*
+static inline PgfItemContss*
pgf_parsing_get_contss(PgfParseState* state, PgfCCat* cat, GuPool *pool)
{
- PgfItemContss* contss = gu_map_get(state->conts_map, cat, PgfItemContss*);
- if (contss == NULL) {
- size_t n_lins = cat->cnccat->n_lins;
- contss = gu_new_seq(PgfItemConts*, n_lins, pool);
- for (size_t i = 0; i < n_lins; i++) {
- gu_seq_set(contss, PgfItemConts*, i, NULL);
- }
- gu_map_put(state->conts_map, cat, PgfItemContss*, contss);
- }
- return contss;
+ return gu_map_get(state->conts_map, cat, PgfItemContss*);
}
static PgfItemConts*
@@ -616,6 +607,15 @@ pgf_parsing_get_conts(PgfParseState* state,
gu_require(lin_idx < ccat->cnccat->n_lins);
PgfItemContss* contss =
pgf_parsing_get_contss(state, ccat, pool);
+ if (contss == NULL) {
+ size_t n_lins = cat->cnccat->n_lins;
+ contss = gu_new_seq(PgfItemConts*, n_lins, pool);
+ for (size_t i = 0; i < n_lins; i++) {
+ gu_seq_set(contss, PgfItemConts*, i, NULL);
+ }
+ gu_map_put(state->conts_map, cat, PgfItemContss*, contss);
+ }
+
PgfItemConts* conts = gu_seq_get(contss, PgfItemConts*, lin_idx);
if (!conts) {
conts = gu_new(PgfItemConts, pool);
@@ -1048,25 +1048,7 @@ pgf_parsing_complete(PgfParsing* ps, PgfItem* item, PgfExprProb *ep)
if (tmp_ccat != NULL) {
PgfItemContss* contss =
pgf_parsing_get_contss(ps->before, ccat, ps->pool);
- size_t n_contss = gu_seq_length(contss);
- for (size_t i = 0; i < n_contss; i++) {
- PgfItemConts* conts2 = gu_seq_get(contss, PgfItemConts*, i);
- /* If there are continuations for
- * linearization index i, then (cat, i) has
- * already been predicted. Add the new
- * production immediately to the agenda,
- * i.e. process it. */
- if (conts2) {
- pgf_parsing_production(ps, ps->before, conts2, prod);
- }
- }
-
- // The category has already been created. If it has also been
- // predicted already, then process a new item for this production.
- PgfParseState* state = ps->after;
- while (state != NULL) {
- PgfItemContss* contss =
- pgf_parsing_get_contss(state, ccat, ps->pool);
+ if (contss != NULL) {
size_t n_contss = gu_seq_length(contss);
for (size_t i = 0; i < n_contss; i++) {
PgfItemConts* conts2 = gu_seq_get(contss, PgfItemConts*, i);
@@ -1076,7 +1058,29 @@ pgf_parsing_complete(PgfParsing* ps, PgfItem* item, PgfExprProb *ep)
* production immediately to the agenda,
* i.e. process it. */
if (conts2) {
- pgf_parsing_production(ps, state, conts2, prod);
+ pgf_parsing_production(ps, ps->before, conts2, prod);
+ }
+ }
+ }
+
+ // The category has already been created. If it has also been
+ // predicted already, then process a new item for this production.
+ PgfParseState* state = ps->after;
+ while (state != NULL) {
+ PgfItemContss* contss =
+ pgf_parsing_get_contss(state, ccat, ps->pool);
+ if (contss != NULL) {
+ size_t n_contss = gu_seq_length(contss);
+ for (size_t i = 0; i < n_contss; i++) {
+ PgfItemConts* conts2 = gu_seq_get(contss, PgfItemConts*, i);
+ /* If there are continuations for
+ * linearization index i, then (cat, i) has
+ * already been predicted. Add the new
+ * production immediately to the agenda,
+ * i.e. process it. */
+ if (conts2) {
+ pgf_parsing_production(ps, state, conts2, prod);
+ }
}
}