]> granicus.if.org Git - re2c/commitdiff
Topsort: always initialize in-degree with zeroes.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 8 Apr 2017 22:04:48 +0000 (23:04 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 8 Apr 2017 22:04:48 +0000 (23:04 +0100)
Don't rely on the fact that topsort leaves all-zero in-degree:
it doesn't if cycles are present. One could manually zero the remaining
entries after topsort, but zero initialization is more reliable.
And it's quite efficient since we only need to initialize the entries
we use.

re2c/src/dfa/tcmd.cc

index ec4d29eeee3e5583ef2870bf1c047c2668a2ccd9..f694631f2638a106bb0a926b01cb2349c0ba38f5 100644 (file)
@@ -85,6 +85,9 @@ void tcmd_t::topsort(tcmd_t **phead, uint32_t *indeg)
                *y0 = NULL, **py, **py1;
 
        // initialize in-degree
+       for (x = x0; x; x = x->next) {
+               indeg[x->lhs] = indeg[depend(x)] = 0;
+       }
        for (x = x0; x; x = x->next) {
                ++indeg[depend(x)];
        }