use std::vector to avoid limiting number of paired characters.

This commit is contained in:
Artem Pavlenko 2019-11-04 13:59:23 +00:00
parent 370f38a2c3
commit 33fac6d47d
2 changed files with 9 additions and 6 deletions

View file

@ -23,9 +23,9 @@
#include <unicode/uobject.h>
#include <unicode/uscript.h>
#pragma GCC diagnostic pop
#include <vector>
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<ParenStackEntry> 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);
}

View file

@ -21,7 +21,6 @@
#pragma GCC diagnostic pop
#include <mapnik/text/scrptrun.hpp>
#include <cstddef>
template <class T, std::size_t N>
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;