A idea to improve diet-ng compile speed!

workman workman at gmail.com
Thu Aug 12 13:45:17 UTC 2021


On Thursday, 12 August 2021 at 07:55:08 UTC, workman wrote:
> D CTFE is great, but not suit for task like dieg-ng.

simple code like this, finish in 0.004s for 20 files. ldc2 take 
hours to finish in product mode.


```c
import diet.defs;
import diet.dom;
import diet.input;
import diet.parser;
import diet.html;

import std.stdio;
import std.file;
import std.path;
int main(string[] args){
	foreach(filepath; args[1..$]){
		scope filename	= baseName(filepath);
		scope ext	= extension(filepath);
		if( ext != ".dt" ) {
			writefln("%s extension %s is not .dt", filepath, ext);
			break;
		}
		scope dfile	= filepath[0..$-1];
		try {
			scope data	= cast(string) read(filepath);
			scope doc	= parseDiet(data, filename);
			scope code	= getHTMLMixin(doc, dietOutputRangeName, 
HTMLOutputStyle.compact);
			if( std.file.exists(dfile) && isFile(dfile) ) {
				scope _code = cast(string) read(dfile);
				if(  _code == code ) continue;

			}
			writefln("%s => %s", filepath, dfile);
			if( is_cached ) {
				continue;
			}
			std.file.write(dfile, code);

		} catch(Exception e) {
			writefln("%s throw %s", filepath, e);
			break;
		}
	}
	return 0;
}

```

dieg not support inherit and layout like 
https://mozilla.github.io/nunjucks/ or 
https://jinja.palletsprojects.com/en/3.0.x/, to add more advance 
function CTFE will  crashed to compile.


More information about the Digitalmars-d mailing list