]> granicus.if.org Git - re2c/commitdiff
Continued adding "--skeleton" switch.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 20 Apr 2015 22:46:29 +0000 (23:46 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 20 Apr 2015 22:46:29 +0000 (23:46 +0100)
Improved readability of overflow checks when counting the number
of paths.

re2c/skeleton.cc
re2c/skeleton.h

index 5e13b46691e2d30724d656f30b4ea62df4deb7ea..7237215d77c0e7fe4b5ebe9b349b18e5565331da 100644 (file)
@@ -5,7 +5,7 @@
 namespace re2c
 {
 
-const uint32_t Skeleton::PATHS_OVERFLOW = 1024 * 1024; // 1Mb
+const uint32_t Skeleton::MAX_PATHS = 1024 * 1024; // 1Mb
 
 Skeleton::Skeleton (const DFA & dfa)
        : states_count (dfa.nStates + 1)
@@ -60,23 +60,21 @@ uint32_t Skeleton::estimate_paths_count (SkeletonState * s, uint32_t count)
        else if (s->visited < 2)
        {
                ++s->visited;
-               uint32_t result = 0;
+               uint64_t result = 0;
                for (SkeletonState::go_t::iterator i = s->go.begin (); i != s->go.end (); ++i)
                {
-                       const uint32_t arrows = i->second.size ();
-                       const uint32_t max_paths = PATHS_OVERFLOW - 1;
-                       if (max_paths / arrows < count)
+                       const uint64_t new_count = i->second.size () * count;
+                       if (new_count >= MAX_PATHS)
                        {
-                               result = PATHS_OVERFLOW;
+                               result = MAX_PATHS;
                                break;
                        }
-                       const uint32_t n = estimate_paths_count (i->first, arrows * count);
-                       if (max_paths - result < n)
+                       result += estimate_paths_count (i->first, new_count);
+                       if (result >= MAX_PATHS)
                        {
-                               result = PATHS_OVERFLOW;
+                               result = MAX_PATHS;
                                break;
                        }
-                       result += n;
                }
                --s->visited;
                return result;
@@ -171,7 +169,7 @@ void Skeleton::generate_paths (std::vector<Path> & results)
        std::vector<Path> prefixes;
        prefixes.push_back (Path (std::vector<uint32_t> (), 0, ~0));
 
-       if (estimate_paths_count (states, 1) == PATHS_OVERFLOW)
+       if (estimate_paths_count (states, 1) == MAX_PATHS)
        {
                // set paths for final states and default state
                // (those with zero outgoing arrows)
index e4c45ae8717d1b3af07fa1bac47a249560957515..3cee73b1ca0a3d687e7d138fa5e2df84ae28715f 100644 (file)
@@ -76,7 +76,7 @@ struct SkeletonState
 
 struct Skeleton
 {
-       static const uint32_t PATHS_OVERFLOW;
+       static const uint32_t MAX_PATHS;
        const uint32_t states_count;
        SkeletonState * states;