[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/9] cex: factor memory allocation
From: |
Akim Demaille |
Subject: |
[PATCH 7/9] cex: factor memory allocation |
Date: |
Sun, 12 Jul 2020 19:23:16 +0200 |
* src/counterexample.c (counterexample_report_state): Allocate once
per conflicted state, instead of once per r/r conflict.
---
src/counterexample.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/counterexample.c b/src/counterexample.c
index 3056ffb9..adb13caa 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -1286,6 +1286,7 @@ counterexample_report_state (const state *s, FILE *out,
const char *prefix)
{
const state_number sn = s->number;
const reductions *reds = s->reductions;
+ bitset lookahead_tokens = bitset_create (ntokens, BITSET_FIXED);
for (int i = 0; i < reds->num; ++i)
{
const rule *r1 = reds->rules[i];
@@ -1300,20 +1301,20 @@ counterexample_report_state (const state *s, FILE *out,
const char *prefix)
}
for (int j = i+1; j < reds->num; ++j)
{
- bitset conf = bitset_create (ntokens, BITSET_FIXED);
const rule *r2 = reds->rules[j];
- bitset_intersection (conf,
+ // Conflicts: common lookaheads.
+ bitset_intersection (lookahead_tokens,
reds->lookahead_tokens[i],
reds->lookahead_tokens[j]);
- if (!bitset_empty_p (conf))
+ if (!bitset_empty_p (lookahead_tokens))
for (state_item_number c2 = state_item_map[sn]; c2 <
state_item_map[sn + 1]; ++c2)
if (!SI_DISABLED (c2)
&& item_rule (state_items[c2].item) == r2)
{
- counterexample_report_reduce_reduce (c1, c2, conf, out,
prefix);
+ counterexample_report_reduce_reduce (c1, c2,
lookahead_tokens, out, prefix);
break;
}
- bitset_free (conf);
}
}
+ bitset_free (lookahead_tokens);
}
--
2.27.0
- [PATCH 0/9] cex: shift derivation vs reduce derivation, Akim Demaille, 2020/07/12
- [PATCH 1/9] tests: beware of version numbers from git describe, Akim Demaille, 2020/07/12
- [PATCH 2/9] cex: minor style changes, Akim Demaille, 2020/07/12
- [PATCH 3/9] cex: use better type names, Akim Demaille, 2020/07/12
- [PATCH 4/9] cex: minor renaming, Akim Demaille, 2020/07/12
- [PATCH 5/9] cex: more consistent memory allocation/copy, Akim Demaille, 2020/07/12
- [PATCH 6/9] cex: use state_item_number consistently, Akim Demaille, 2020/07/12
- [PATCH 7/9] cex: factor memory allocation,
Akim Demaille <=
- [PATCH 8/9] style: s/lookahead_tokens/lookaheads/g, Akim Demaille, 2020/07/12
- [PATCH 9/9] cex: display shifts before reductions, Akim Demaille, 2020/07/12