summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-24 12:52:12 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-27 09:36:20 -0800
commit73c5d5c00aa6e7c8a2702492b5074c2211edc94e (patch)
tree5804d42e199f83bd30011f02c0ecc161d3112ac0 /platform/default
parent92e6e48699f5f94a80d69a94202f0f9c803fa2a7 (diff)
downloadqtlocation-mapboxgl-73c5d5c00aa6e7c8a2702492b5074c2211edc94e.tar.gz
[core] Avoid some string copies in bidi implementation
As of C++11, it's safe to preallocate std::[u16]string and write to the buffer via &s[0] (C++17 makes it possible via .data() as well).
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/bidi.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/platform/default/bidi.cpp b/platform/default/bidi.cpp
index eb4e658733..64baddaa5b 100644
--- a/platform/default/bidi.cpp
+++ b/platform/default/bidi.cpp
@@ -36,8 +36,9 @@ std::u16string applyArabicShaping(const std::u16string& input) {
// Pre-flighting will always set U_BUFFER_OVERFLOW_ERROR
errorCode = U_ZERO_ERROR;
- auto outputText = std::make_unique<UChar[]>(outputLength);
- u_shapeArabic(input.c_str(), static_cast<int32_t>(input.size()), outputText.get(), outputLength,
+ std::u16string outputText(outputLength, 0);
+
+ u_shapeArabic(input.c_str(), static_cast<int32_t>(input.size()), &outputText[0], outputLength,
(U_SHAPE_LETTERS_SHAPE & U_SHAPE_LETTERS_MASK) |
(U_SHAPE_TEXT_DIRECTION_LOGICAL & U_SHAPE_TEXT_DIRECTION_MASK),
&errorCode);
@@ -46,7 +47,7 @@ std::u16string applyArabicShaping(const std::u16string& input) {
if (U_FAILURE(errorCode))
return input;
- return std::u16string(outputText.get(), outputLength);
+ return outputText;
}
void BiDi::mergeParagraphLineBreaks(std::set<size_t>& lineBreakPoints) {
@@ -108,12 +109,12 @@ std::u16string BiDi::getLine(std::size_t start, std::size_t end) {
// Setting UBIDI_INSERT_LRM_FOR_NUMERIC would require
// ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)
const int32_t outputLength = ubidi_getProcessedLength(impl->bidiLine);
- auto outputText = std::make_unique<UChar[]>(outputLength);
+ std::u16string outputText(outputLength, 0);
// UBIDI_DO_MIRRORING: Apply unicode mirroring of characters like parentheses
// UBIDI_REMOVE_BIDI_CONTROLS: Now that all the lines are set, remove control characters so that
// they don't show up on screen (some fonts have glyphs representing them)
- ubidi_writeReordered(impl->bidiLine, outputText.get(), outputLength,
+ ubidi_writeReordered(impl->bidiLine, &outputText[0], outputLength,
UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &errorCode);
if (U_FAILURE(errorCode)) {
@@ -121,7 +122,7 @@ std::u16string BiDi::getLine(std::size_t start, std::size_t end) {
u_errorName(errorCode));
}
- return std::u16string(outputText.get(), outputLength);
+ return outputText;
}
} // end namespace mbgl