Merge pull request #259 from wilzbach/update-dustmite

Update DustMite to 7403f0d053b96b2c21950df038923b5d335d557f
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2017-10-05 14:19:52 +02:00 committed by Martin Nowak
parent 599600c391
commit 9dde9afb4b
2 changed files with 65 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import std.array;
import std.ascii;
import std.conv;
import std.datetime;
import std.datetime.stopwatch : StopWatch;
import std.exception;
import std.file;
import std.getopt;
@ -278,7 +279,7 @@ EOS");
else
reduce();
auto duration = cast(Duration)times.total.peek();
auto duration = times.total.peek();
duration = dur!"msecs"(duration.total!"msecs"); // truncate anything below ms, users aren't interested in that
if (foundAnything)
{
@ -296,7 +297,7 @@ EOS");
if (showTimes)
foreach (i, t; times.tupleof)
writefln("%s: %s", times.tupleof[i].stringof, cast(Duration)times.tupleof[i].peek());
writefln("%s: %s", times.tupleof[i].stringof, times.tupleof[i].peek());
return 0;
}
@ -1424,9 +1425,17 @@ bool test(Reduction reduction)
{
if (!process.pid && !lookaheadIter.done)
{
auto initialReduction = lookaheadIter.front;
bool first = true;
while (true)
{
auto reduction = lookaheadIter.front;
if (!first && reduction == initialReduction)
break; // We've looped around using cached results
first = false;
auto digest = hash(reduction);
if (digest in cache || digest in lookaheadResults || lookaheadProcesses[].canFind!(p => p.digest == digest))

View file

@ -8,6 +8,7 @@ import std.ascii;
import std.algorithm;
import std.array;
import std.conv;
import std.exception;
import std.file;
import std.functional;
import std.path;
@ -77,6 +78,7 @@ enum Splitter
lines, /// Split by line ends
words, /// Split by whitespace
D, /// Parse D source code
diff, /// Unified diffs
}
immutable string[] splitterNames = [EnumMembers!Splitter].map!(e => e.text().toLower()).array();
@ -166,9 +168,11 @@ string strip(string s) { while (s.length && isWhite(s[0])) s = s[1..$]; while (s
immutable ParseRule[] defaultRules =
[
{ "*.d" , Splitter.D },
{ "*.di", Splitter.D },
{ "*" , Splitter.files },
{ "*.d" , Splitter.D },
{ "*.di" , Splitter.D },
{ "*.diff" , Splitter.diff },
{ "*.patch", Splitter.diff },
{ "*" , Splitter.files },
];
Entity loadFile(string name, string path, ParseOptions options)
@ -212,6 +216,9 @@ Entity loadFile(string name, string path, ParseOptions options)
return result;
}
}
case Splitter.diff:
result.children = parseDiff(result.contents);
return result;
}
}
assert(false); // default * rule should match everything
@ -1190,6 +1197,50 @@ Entity[] parseSplit(alias fun)(string text)
alias parseToWords = parseSplit!isNotAlphaNum;
alias parseToLines = parseSplit!isNewline;
/// Split s on end~start, preserving end and start on each chunk
private string[] split2(string end, string start)(string s)
{
enum sep = end ~ start;
return split2Impl(s, sep, end.length);
}
private string[] split2Impl(string s, string sep, size_t endLength)
{
string[] result;
while (true)
{
auto i = s.indexOf(sep);
if (i < 0)
return result ~ s;
i += endLength;
result ~= s[0..i];
s = s[i..$];
}
}
unittest
{
assert(split2!("]", "[")(null) == [""]);
assert(split2!("]", "[")("[foo]") == ["[foo]"]);
assert(split2!("]", "[")("[foo][bar]") == ["[foo]", "[bar]"]);
assert(split2!("]", "[")("[foo] [bar]") == ["[foo] [bar]"]);
}
Entity[] parseDiff(string s)
{
return s
.split2!("\n", "diff ")
.map!(
(string file)
{
auto chunks = file.split2!("\n", "@@ ");
return new Entity(chunks[0], chunks[1..$].map!(chunk => new Entity(chunk)).array);
}
)
.array
;
}
private:
bool isNewline(char c) { return c == '\r' || c == '\n'; }