]> granicus.if.org Git - re2c/commitdiff
Code cleanup.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 Apr 2015 15:43:16 +0000 (16:43 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 Apr 2015 15:43:16 +0000 (16:43 +0100)
re2c/skeleton.cc
re2c/skeleton.h

index a65bc7029517d4db16e8972a23839067cb1a8e91..5f1840c0edb2d2adc1f1bb7a9fb692b86a120fea 100644 (file)
@@ -39,9 +39,7 @@ Skeleton::~Skeleton ()
 
 unsigned long count_data (SkeletonState * s, unsigned long count)
 {
-       const bool is_default = s == NULL;
-       const bool is_final = !is_default && s->go.size () == 1 && s->go.begin ()->first == NULL;
-       if (is_final || is_default)
+       if (is_final (s) || is_default (s))
        {
                return count;
        }
@@ -74,9 +72,7 @@ unsigned long Skeleton::count ()
 
 void generate_data (DataFile & o, uint ind, SkeletonState * s, const std::vector<Prefix> & xs, std::vector<Result> & ys)
 {
-       const bool is_default = s == NULL;
-       const bool is_final = !is_default && s->go.size () == 1 && s->go.begin ()->first == NULL;
-       if (is_final || is_default)
+       if (is_final (s) || is_default (s))
        {
                for (uint i = 0; i < xs.size (); ++i)
                {
@@ -88,10 +84,10 @@ void generate_data (DataFile & o, uint ind, SkeletonState * s, const std::vector
                        }
                        o.file << "\n";
                        const uint processed = xs[i].chars.size ();
-                       const uint consumed = is_final
+                       const uint consumed = is_final (s)
                                ? xs[i].chars.size ()
                                : xs[i].length;
-                       const uint rule = is_final
+                       const uint rule = is_final (s)
                                ? s->rule
                                : xs[i].rule;
                        ys.push_back (Result (processed, consumed, rule));
index f8403be44b330a8fc4c642aa1b81a5d28eeae95e..d0b1256eb6a207a8aeac15439d86cda3e64877c8 100644 (file)
@@ -18,6 +18,18 @@ struct SkeletonState
        bool visited;
 };
 
+inline bool is_default (SkeletonState * s)
+{
+       return s == NULL;
+}
+
+inline bool is_final (SkeletonState * s)
+{
+       return s != NULL
+               && s->go.size () == 1
+               && s->go.begin ()->first == NULL;
+}
+
 struct Prefix
 {
        std::vector<uint> chars;