Skip to content

Commit c77b870

Browse files
committed
Experimental: one thread per stat call
1 parent 0124c6b commit c77b870

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

rdmd.d

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import std.algorithm, std.array, std.c.stdlib, std.datetime,
44
std.exception, std.file, std.getopt,
5-
std.md5, std.path, std.process, std.regex,
5+
std.md5, std.parallelism, std.path, std.process, std.regex,
66
std.stdio, std.string, std.typetuple;
77

88
version (Posix)
@@ -202,8 +202,7 @@ int main(string[] args)
202202
}
203203

204204
// Have at it
205-
if (isNewer(root, exe) ||
206-
std.algorithm.canFind!(a => isNewer(a, exe))(myDeps.keys))
205+
if (isNewer(root, exe) || anyNewerThan(myDeps.keys, exe))
207206
{
208207
immutable result = rebuild(root, exe, objDir, myDeps, compilerFlags,
209208
addStubMain);
@@ -455,15 +454,7 @@ private string[string] getDependencies(string rootModule, string objDir,
455454
{
456455
// See if the deps file is still in good shape
457456
auto deps = readDepsFile();
458-
bool mustRebuildDeps;
459-
foreach (source, _; deps)
460-
{
461-
if (isNewer(source, depsFilename))
462-
{
463-
mustRebuildDeps = true;
464-
break;
465-
}
466-
}
457+
bool mustRebuildDeps = anyNewerThan(deps.keys, depsFilename);
467458
if (!mustRebuildDeps)
468459
{
469460
// Cool, we're in good shape
@@ -498,6 +489,32 @@ private string[string] getDependencies(string rootModule, string objDir,
498489
return readDepsFile();
499490
}
500491

492+
// Is any file newer than the given file?
493+
bool anyNewerThan(in string[] files, in string file)
494+
{
495+
// Experimental: running isNewer in separate threads, one per file
496+
if (false)
497+
{
498+
foreach (source; files)
499+
{
500+
if (isNewer(source, file))
501+
{
502+
return true;
503+
}
504+
}
505+
return false;
506+
} else {
507+
foreach (source; taskPool.parallel(files, 1))
508+
{
509+
if (isNewer(source, file))
510+
{
511+
return true;
512+
}
513+
}
514+
return false;
515+
}
516+
}
517+
501518
// Quote an argument in a manner conforming to the behavior of
502519
// CommandLineToArgvW and DMD's response-file parsing algorithm.
503520
// References:

0 commit comments

Comments
 (0)