Making regex replace CTFE by removing malloc

Pierre Krafft via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 3 08:04:38 PDT 2015


On Friday, 3 April 2015 at 03:58:33 UTC, ketmar wrote:
> On Thu, 02 Apr 2015 17:14:24 +0000, Pierre Krafft wrote:
>
>> What can replace malloc that can run on compile time and won't 
>> make it
>> slower at run time?
>
> this is actually two questions, so i'll answer to two questions.
>
> 1. What can replace malloc that can run on compile time?
> new ubyte[](size)
>
> 2. ...and won't make it slower at run time?
> but we can still use malloc in runtime! `if (_ctfe)` allows us 
> to select
> the necessary code branch.
>
> p.s. i don't think that this is the only problem, though. but i 
> never
> read "std.regexp" source. it's bad, 'cause i want to make it 
> work with
> any range, not only with strings. this will allow to run regexp 
> on
> anything -- and open way to my rbtree-based document system.

It seems like I have treaded into something which is outside my 
knowledge domain. The malloc is indeed one of the least problems 
with that code. The code makes use of completely unsafe code with 
pointer casts that are disallowed in CTFE code. If someone knows 
how to replace the pointer casts that would probably be 
everything needed. Otherwise I think it would need a rewrite to 
make it use safe D. The new code would probably be slower so for 
most people it would be a step back. A solution would be to have 
different code for CTFE and runtime but that seems unmaintainable 
and subpar.


More information about the Digitalmars-d mailing list