How to avoid ctRegex (solved)

Seb via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 24 07:31:50 PDT 2016


On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote:
> On 08/24/2016 03:07 AM, cy wrote:
>> Then what's ctRegex in there for at all...?
>
> Optimization.
>
> ctRegex requires that the pattern is available as a compile 
> time constant. It uses that property to "generate optimized 
> native machine code".
>
> The plain regex function doesn't have such a requirement. It 
> also works with a pattern that's generated at run time, e.g. 
> from user input. But you can use it with a compile time 
> constant, too. And it works in CTFE then, but it does not 
> "generate optimized native machine code".

Yep, that's why ctRegex is 2x faster than the highly-tuned grep, 
e.g.

https://github.com/dlang/phobos/pull/4286


More information about the Digitalmars-d-learn mailing list