From 746de934f2de7b6c53047a3f8feeb6ebb9638996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Wed, 30 Jul 2025 10:35:39 +0100 Subject: [PATCH] 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. --- pegged/peg.d | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pegged/peg.d b/pegged/peg.d index b913a88..173a487 100644 --- a/pegged/peg.d +++ b/pegged/peg.d @@ -1664,9 +1664,9 @@ template or(rules...) if (rules.length > 0) size_t errorStringChars; string orErrorString; - ParseTree[rules.length] results; - string[rules.length] names; - size_t[rules.length] failedLength; + ParseTree[] results = new ParseTree[rules.length]; + string[] names = new string[rules.length]; + size_t[] failedLength = new size_t[rules.length]; size_t maxFailedLength; version (tracer) @@ -1858,9 +1858,9 @@ template longest_match(rules...) if (rules.length > 0) size_t errorStringChars; string orErrorString; - ParseTree[rules.length] results; - string[rules.length] names; - size_t[rules.length] failedLength; + ParseTree[] results = new ParseTree[rules.length]; + string[] names = new string[rules.length]; + size_t[] failedLength = new size_t[rules.length]; size_t maxFailedLength; version (tracer)