[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/6] tables: scope reduction
From: |
Akim Demaille |
Subject: |
[PATCH 6/6] tables: scope reduction |
Date: |
Thu, 27 Dec 2012 09:25:49 +0100 |
* src/tables.c (matching_state): here.
---
src/tables.c | 70 ++++++++++++++++++++++++++++--------------------------------
1 file changed, 33 insertions(+), 37 deletions(-)
diff --git a/src/tables.c b/src/tables.c
index f99f07b..c623301 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -620,47 +620,43 @@ static state_number
matching_state (vector_number vector)
{
vector_number i = order[vector];
- size_t t;
- int w;
- int prev;
-
/* If VECTOR is a nterm, return -1. */
- if (nstates <= i)
- return -1;
-
- t = tally[i];
- w = width[i];
-
- /* If VECTOR has GLR conflicts, return -1 */
- if (conflict_tos[i] != NULL)
+ if (i < nstates)
{
- int j;
- for (j = 0; j < t; j += 1)
- if (conflict_tos[i][j] != 0)
- return -1;
- }
+ size_t t = tally[i];
+ int w = width[i];
+ int prev;
- for (prev = vector - 1; prev >= 0; prev--)
- {
- vector_number j = order[prev];
- int k;
- int match = 1;
-
- /* Given how ORDER was computed, if the WIDTH or TALLY is
- different, there cannot be a matching state. */
- if (width[j] != w || tally[j] != t)
- return -1;
-
- for (k = 0; match && k < t; k++)
- if (tos[j][k] != tos[i][k]
- || froms[j][k] != froms[i][k]
- || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
- match = 0;
-
- if (match)
- return j;
- }
+ /* If VECTOR has GLR conflicts, return -1 */
+ if (conflict_tos[i] != NULL)
+ {
+ int j;
+ for (j = 0; j < t; j += 1)
+ if (conflict_tos[i][j] != 0)
+ return -1;
+ }
+ for (prev = vector - 1; 0 <= prev; prev--)
+ {
+ vector_number j = order[prev];
+ /* Given how ORDER was computed, if the WIDTH or TALLY is
+ different, there cannot be a matching state. */
+ if (width[j] != w || tally[j] != t)
+ return -1;
+ else
+ {
+ bool match = true;
+ int k;
+ for (k = 0; match && k < t; k++)
+ if (tos[j][k] != tos[i][k]
+ || froms[j][k] != froms[i][k]
+ || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
+ match = false;
+ if (match)
+ return j;
+ }
+ }
+ }
return -1;
}
--
1.8.0.2
- [PATCH 0/6] {master} internals: improve readability, Akim Demaille, 2012/12/27
- [PATCH 1/6] tables: style changes, Akim Demaille, 2012/12/27
- [PATCH 5/6] tables: scope reduction, Akim Demaille, 2012/12/27
- [PATCH 4/6] tables: scope reduction, Akim Demaille, 2012/12/27
- [PATCH 2/6] tables: use size_t where appropriate, Akim Demaille, 2012/12/27
- [PATCH 3/6] tables: scope reduction, Akim Demaille, 2012/12/27
- [PATCH 6/6] tables: scope reduction,
Akim Demaille <=
- Re: [PATCH 0/6] {master} internals: improve readability, Akim Demaille, 2012/12/27