]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: simplify constraint-dependency checking
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 2 Jan 2017 05:43:26 +0000 (21:43 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 2 Jan 2017 05:43:57 +0000 (21:43 -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
lib/dfa.c

index 85436e1c0527a2806844ce0df8d348536105ca31..2b8cbc11bc4111e8bb6b3e129923ac031945313c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2017-01-01  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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)
index 5b9de5381693e454e43dd980fbbd8f91cd0ed18f..cd600aa1e630cfd441969a76f305357712fb6166 100644 (file)
--- 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