[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] dfa: simplify constraint-dependency checking
From: |
Paul Eggert |
Subject: |
[PATCH 2/2] dfa: simplify constraint-dependency checking |
Date: |
Sun, 1 Jan 2017 21:45:14 -0800 |
* lib/dfa.c (prev_newline_constraint, prev_letter_constraint)
(prev_other_constraint): Remove.
(prev_newline_dependent, prev_letter_dependent):
Simplify, to avoid an unnecessary bitwise AND operation.
---
ChangeLog | 6 ++++++
lib/dfa.c | 22 ++--------------------
2 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 85436e1..2b8cbc1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2017-01-01 Paul Eggert <address@hidden>
+ dfa: simplify constraint-dependency checking
+ * lib/dfa.c (prev_newline_constraint, prev_letter_constraint)
+ (prev_other_constraint): Remove.
+ (prev_newline_dependent, prev_letter_dependent):
+ Simplify, to avoid an unnecessary bitwise AND operation.
+
dfa: prefer functions and constants to macros
* lib/dfa.c: Prefer constants to macros where either will do.
(streq, isasciidigit, newline_constraint)
diff --git a/lib/dfa.c b/lib/dfa.c
index 5b9de53..cd600aa 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -175,33 +175,15 @@ succeeds_in_context (int constraint, int prev, int curr)
}
/* The following describe what a constraint depends on. */
-static int
-prev_newline_constraint (int constraint)
-{
- return (constraint >> 2) & 0x111;
-}
-static int
-prev_letter_constraint (int constraint)
-{
- return (constraint >> 1) & 0x111;
-}
-static int
-prev_other_constraint (int constraint)
-{
- return constraint & 0x111;
-}
-
static bool
prev_newline_dependent (int constraint)
{
- return (prev_newline_constraint (constraint)
- != prev_other_constraint (constraint));
+ return ((constraint ^ constraint >> 2) & 0x111) != 0;
}
static bool
prev_letter_dependent (int constraint)
{
- return (prev_letter_constraint (constraint)
- != prev_other_constraint (constraint));
+ return ((constraint ^ constraint >> 1) & 0x111) != 0;
}
/* Tokens that match the empty string subject to some constraint actually
--
2.7.4