From a38c9c7aeebe61197c48371bb5085e45727bb7e5 Mon Sep 17 00:00:00 2001 From: jules Date: Sat, 31 Oct 2015 14:58:03 +0000 Subject: [PATCH] Made TextDiff use less stack space --- modules/juce_core/text/juce_TextDiff.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/text/juce_TextDiff.cpp b/modules/juce_core/text/juce_TextDiff.cpp index 4b07015b2b..a8bff4e7ee 100644 --- a/modules/juce_core/text/juce_TextDiff.cpp +++ b/modules/juce_core/text/juce_TextDiff.cpp @@ -116,7 +116,21 @@ struct TextDiffHelpers b, lenB, indexInB); const size_t scratchSpace = sizeof (int) * (2 + 2 * (size_t) lenB); - int* const lines = (int*) alloca (scratchSpace); + + if (scratchSpace < 4096) + { + int* scratch = (int*) alloca (scratchSpace); + return findLongestCommonSubstring (a, lenA, indexInA, b, lenB, indexInB, scratchSpace, scratch); + } + + HeapBlock scratch (scratchSpace); + return findLongestCommonSubstring (a, lenA, indexInA, b, lenB, indexInB, scratchSpace, scratch); + } + + static int findLongestCommonSubstring (String::CharPointerType a, const int lenA, int& indexInA, + String::CharPointerType b, const int lenB, int& indexInB, + const size_t scratchSpace, int* const lines) noexcept + { zeromem (lines, scratchSpace); int* l0 = lines;