summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-12-03 14:45:17 -0500
committerAdrian Thurston <thurston@complang.org>2014-12-03 14:45:17 -0500
commitd54748056f81e646e6b786c285fca1590d9f2e68 (patch)
tree7d8a530b4991cacfa32319d85947c34380501c0c
parent0d113943c37e1d361986cdcc6abbce5159afe94c (diff)
downloadragel-6-alt-default.tar.gz
alternate default choice, first or last, whiciver is biggerragel-6-alt-default
An alternate default span choice strategy: the first or the last, whichever is bigger. refs #27
-rw-r--r--ragel/redfsm.cpp33
1 files changed, 7 insertions, 26 deletions
diff --git a/ragel/redfsm.cpp b/ragel/redfsm.cpp
index 9a58752b..71bd88ab 100644
--- a/ragel/redfsm.cpp
+++ b/ragel/redfsm.cpp
@@ -388,34 +388,15 @@ bool RedFsmAp::alphabetCovered( RedTransList &outRange )
RedTransAp *RedFsmAp::chooseDefaultSpan( RedStateAp *state )
{
- /* Make a set of transitions from the outRange. */
- RedTransSet stateTransSet;
- for ( RedTransList::Iter rtel = state->outRange; rtel.lte(); rtel++ )
- stateTransSet.insert( rtel->value );
-
- /* For each transition in the find how many alphabet characters the
- * transition spans. */
- unsigned long long *span = new unsigned long long[stateTransSet.length()];
- memset( span, 0, sizeof(unsigned long long) * stateTransSet.length() );
- for ( RedTransList::Iter rtel = state->outRange; rtel.lte(); rtel++ ) {
- /* Lookup the transition in the set. */
- RedTransAp **inSet = stateTransSet.find( rtel->value );
- int pos = inSet - stateTransSet.data;
- span[pos] += keyOps->span( rtel->lowKey, rtel->highKey );
- }
+ long long span1 = keyOps->span( state->outRange[0].lowKey,
+ state->outRange[0].lowKey );
- /* Find the max span, choose it for making the default. */
- RedTransAp *maxTrans = 0;
- unsigned long long maxSpan = 0;
- for ( RedTransSet::Iter rtel = stateTransSet; rtel.lte(); rtel++ ) {
- if ( span[rtel.pos()] > maxSpan ) {
- maxSpan = span[rtel.pos()];
- maxTrans = *rtel;
- }
- }
+ long long span2 = keyOps->span( state->outRange[state->outRange.length()-1].lowKey,
+ state->outRange[state->outRange.length()-1].lowKey );
- delete[] span;
- return maxTrans;
+ return span1 > span2 ?
+ state->outRange[0].value :
+ state->outRange[state->outRange.length()-1].value;
}
/* Pick default transitions from ranges for the states. */