import std.stdio : writeln, writefln;
import std.range : take, array, join;
import std.algorithm : map, filter, splitter;
import std.regex;
import std.datetime;
auto stopTime(alias F)() {
auto sw = StopWatch(AutoStart.yes);
// writeln(F("big.txt"));
writeln(F("big.txt").length);
sw.stop();
return sw.peek.msecs;
}
auto search(string pattern)(string file) {
auto r = ctRegex!(pattern);
import std.mmfile : MmFile;
import std.file : getSize;
auto sz = getSize(file);
auto mmf = new MmFile(file, MmFile.Mode.read, sz, null);
//mmfile bug??
import core.memory : GC;
GC.addRoot(mmf[].ptr);
scope(exit){
GC.removeRoot(mmf[].ptr);
}
static auto matchLine(T)(T reg){
return reg["name"]
.splitter!(a => a == ' ' || a == ';' || a == '\"')
.filter!(a => a != """")
.join(".");
}
import std.string : lineSplitter;
return (cast(string)mmf[])
.lineSplitter()
.take(10_000_000)
.map!(a => a.matchFirst(r))
.filter!(a => !a.empty)
.map!(matchLine)
.array;
}
int main(string[] argv) {
auto elapsed = stopTime!(search!(r"\{.*(?P<name>Microsoft.*)\|\]"));
writefln("Elapsed: %s", elapsed);
return 0;
}