summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-09-16 10:38:04 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-09-16 12:09:23 +0200
commit16d645e5b8f11b4ddb49a2b58bde388b28960abc (patch)
treef0c9ef755fbeefd94976f9a687fd9028b9789e68 /i18npool
parentb2db17e8c0bb64e33ecf2d074a542568fc66451a (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/transliteration/transliteration_body.cxx7
1 files changed, 5 insertions, 2 deletions
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();