diff --git a/include/mapnik/text/scrptrun.hpp b/include/mapnik/text/scrptrun.hpp index 7cee74197..d7e7b0bf6 100644 --- a/include/mapnik/text/scrptrun.hpp +++ b/include/mapnik/text/scrptrun.hpp @@ -23,9 +23,9 @@ #include #include #pragma GCC diagnostic pop +#include const unsigned int STACK_SIZE = 1 << 7; // 2^n -const unsigned int STACK_MASK = STACK_SIZE - 1; struct ScriptRecord { @@ -36,6 +36,8 @@ struct ScriptRecord struct ParenStackEntry { + ParenStackEntry(int32_t pairIndex_, UScriptCode scriptCode_) + : pairIndex(pairIndex_), scriptCode(scriptCode_) {} int32_t pairIndex = 0; UScriptCode scriptCode = USCRIPT_INVALID_CODE; }; @@ -88,7 +90,7 @@ private: int32_t scriptEnd; UScriptCode scriptCode; - ParenStackEntry parenStack[STACK_SIZE]; + std::vector parenStack; int32_t parenSP; static int8_t highBit(int32_t value); @@ -108,16 +110,19 @@ private: inline ScriptRun::ScriptRun() { + parenStack.reserve(STACK_SIZE); reset(nullptr, 0, 0); } inline ScriptRun::ScriptRun(const UChar chars[], int32_t length) { + parenStack.reserve(STACK_SIZE); reset(chars, 0, length); } inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length) { + parenStack.reserve(STACK_SIZE); reset(chars, start, length); } diff --git a/src/text/scrptrun.cpp b/src/text/scrptrun.cpp index 4dd25eb03..071b7b239 100644 --- a/src/text/scrptrun.cpp +++ b/src/text/scrptrun.cpp @@ -21,7 +21,6 @@ #pragma GCC diagnostic pop #include -#include template constexpr std::size_t ARRAY_SIZE(const T (&array)[N]) noexcept @@ -161,9 +160,8 @@ UBool ScriptRun::next() // characters above it on the stack will be poped. if (pairIndex >= 0) { if ((pairIndex & 1) == 0) { - parenSP = (parenSP + 1) & STACK_MASK; // avoid out-of-bounds access - parenStack[parenSP].pairIndex = pairIndex; - parenStack[parenSP].scriptCode = scriptCode; + ++parenSP; + parenStack.emplace_back(pairIndex, scriptCode); } else if (parenSP >= 0) { int32_t pi = pairIndex & ~1;