File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,29 @@ CharMatcher[CodepointSet] matcherCache;
49
49
}
50
50
}
51
51
52
- @property ref wordMatcher()()
52
+ // Force pure because that is needed
53
+ // Templated so that we don't pull in std.uni wordCharacter unnecessarily.
54
+ @property ref wordMatcher()() pure
53
55
{
54
- static immutable CharMatcher matcher = CharMatcher(wordCharacter);
55
- return matcher;
56
+ static auto actual ()
57
+ {
58
+ static CharMatcher matcher;
59
+ static bool haveMatcher;
60
+
61
+ if (! haveMatcher)
62
+ {
63
+ matcher = CharMatcher(wordCharacter);
64
+ haveMatcher = true ;
65
+ }
66
+
67
+ return &matcher;
68
+ }
69
+
70
+ // WORKAROUND: if the compiler won't memoize the output of the function for us,
71
+ // we'll do it with pure and there will be casts and it'll be happy about it.
72
+ // This is unfortunately needed to make std.regex as a whole faster to import & use
73
+ // in build times ~500ms.
74
+ return * (cast (immutable (CharMatcher)* function () @safe nothrow @nogc pure )&actual)();
56
75
}
57
76
58
77
// some special Unicode white space characters
You can’t perform that action at this time.
0 commit comments