i18npool/source/transliteration/transliteration_body.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
New commits: commit 16d645e5b8f11b4ddb49a2b58bde388b28960abc Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Sep 16 10:38:04 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Sep 16 12:09:23 2021 +0200 speedup Transliteration_body::transliterateImpl use alloca in Transliteration_body::transliterateImpl to avoid over-allocating stack-space (which tends to unnecessarily flush some cache) Change-Id: I1843fdcb830a3e948a8bbd0a9c7eb143b21a804c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122184 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/i18npool/source/transliteration/transliteration_body.cxx b/i18npool/source/transliteration/transliteration_body.cxx index 9fd89df75e42..3581212af8b3 100644 --- a/i18npool/source/transliteration/transliteration_body.cxx +++ b/i18npool/source/transliteration/transliteration_body.cxx @@ -102,9 +102,12 @@ Transliteration_body::transliterateImpl( // Allocate the max possible buffer. Try to use stack instead of heap, // which would have to be reallocated most times anyways. constexpr sal_Int32 nLocalBuf = 2048; - sal_Unicode aLocalBuf[ nLocalBuf * NMAPPINGMAX ], *out = aLocalBuf; + sal_Unicode* out; std::unique_ptr<sal_Unicode[]> pHeapBuf; - if (nCount > nLocalBuf) + size_t nBytes = (nCount + 1) * sizeof(sal_Unicode); + if (nBytes <= nLocalBuf * NMAPPINGMAX) + out = static_cast<sal_Unicode*>(alloca(nBytes)); + else { pHeapBuf.reset(new sal_Unicode[ nCount * NMAPPINGMAX ]); out = pHeapBuf.get();