Skip to content

Commit c351440

Browse files
ljmf00-wekaioveelo
authored andcommitted
fix(peg): use GC allocated slice instead of always alloca on stack
On big `or!()` templates stack size can grow pretty fast, specially when recursion is done on similar templates and recursive tail call optimizations are not possible. For performance, LDC compiler already optimizes these calls into stack-based variables when they are too small. Regardless, this library heavily uses GC on the inner strings, so the impact is negligable.
1 parent f12b0bd commit c351440

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pegged/peg.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,9 +1664,9 @@ template or(rules...) if (rules.length > 0)
16641664
size_t errorStringChars;
16651665
string orErrorString;
16661666
1667-
ParseTree[rules.length] results;
1668-
string[rules.length] names;
1669-
size_t[rules.length] failedLength;
1667+
ParseTree[] results = new ParseTree[rules.length];
1668+
string[] names = new string[rules.length];
1669+
size_t[] failedLength = new size_t[rules.length];
16701670
size_t maxFailedLength;
16711671
16721672
version (tracer)
@@ -1858,9 +1858,9 @@ template longest_match(rules...) if (rules.length > 0)
18581858
size_t errorStringChars;
18591859
string orErrorString;
18601860
1861-
ParseTree[rules.length] results;
1862-
string[rules.length] names;
1863-
size_t[rules.length] failedLength;
1861+
ParseTree[] results = new ParseTree[rules.length];
1862+
string[] names = new string[rules.length];
1863+
size_t[] failedLength = new size_t[rules.length];
18641864
size_t maxFailedLength;
18651865
18661866
version (tracer)

0 commit comments

Comments
 (0)