@@ -256,28 +256,64 @@ distloop:
256256 // find all the non-trivial dependencies (that is, dependencies that have a
257257 // ctor or dtor) of a given module. Doing this, we can 'skip over' the
258258 // trivial modules to get at the non-trivial ones.
259- size_t _findDependencies (int idx, bool orig = true )
259+ size_t _findDependencies (int idx)
260260 {
261+ static struct stackFrame
262+ {
263+ int curMod;
264+ int curDep;
265+ }
266+
267+ // initialize "stack"
268+ auto stack = cast (stackFrame * )alloca(stackFrame.sizeof * len);
269+ auto stacktop = stack + len;
270+ auto sp = stack;
271+ sp.curMod = idx;
272+ sp.curDep = 0 ;
261273 size_t result = 0 ;
262- foreach (m; _modules[idx].importedModules)
274+
275+ for (;;)
263276 {
264- auto midx = findModule(m);
277+ auto m = _modules[sp.curMod];
278+ if (sp.curDep >= m.importedModules.length)
279+ {
280+ // return
281+ if (sp == stack)
282+ // finished the algorithm
283+ break ;
284+ -- sp;
285+ ++ sp.curDep;
286+ continue ;
287+ }
288+ auto midx = findModule(m.importedModules[sp.curDep]);
265289 // if midx is -1, then this isn't part of this DSO.
266- if (midx != - 1 )
267- if (! bts(reachable, midx))
290+ if (midx != - 1 && ! bts(reachable, midx))
291+ {
292+ if (bt(relevant, midx))
268293 {
269- if (bt(relevant, midx))
270- {
271- // non-trivial, stop here
272- result += 1 ;
273- }
274- else if (! bt(ctordone, midx))
294+ // non-trivial, stop here
295+ result += 1 ;
296+ }
297+ else if (! bt(ctordone, midx))
298+ {
299+ // non-relevant, and hasn't been exhaustively processed, recurse.
300+ if (! bt(ctorstart, midx))
301+ ++ result;
302+ // recurse
303+ if (++ sp >= stacktop)
275304 {
276- // non-relevant, and hasn 't been exhaustively processed, recurse .
277- result += ( ! bt(ctorstart, midx) ? 1 : 0 ) +
278- _findDependencies(midx, false );
305+ // stack overflow, this shouldn 't happen .
306+ import core.internal.abort : abort;
307+ abort( " stack overflow on dependency search " );
279308 }
309+ sp.curMod = midx;
310+ sp.curDep = 0 ;
311+ continue ;
280312 }
313+ }
314+
315+ // next dependency
316+ ++ sp.curDep;
281317 }
282318 return result;
283319 }
0 commit comments