use std::vector to avoid limiting number of paired characters.
This commit is contained in:
parent
370f38a2c3
commit
33fac6d47d
2 changed files with 9 additions and 6 deletions
|
@ -23,9 +23,9 @@
|
||||||
#include <unicode/uobject.h>
|
#include <unicode/uobject.h>
|
||||||
#include <unicode/uscript.h>
|
#include <unicode/uscript.h>
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
const unsigned int STACK_SIZE = 1 << 7; // 2^n
|
const unsigned int STACK_SIZE = 1 << 7; // 2^n
|
||||||
const unsigned int STACK_MASK = STACK_SIZE - 1;
|
|
||||||
|
|
||||||
struct ScriptRecord
|
struct ScriptRecord
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,8 @@ struct ScriptRecord
|
||||||
|
|
||||||
struct ParenStackEntry
|
struct ParenStackEntry
|
||||||
{
|
{
|
||||||
|
ParenStackEntry(int32_t pairIndex_, UScriptCode scriptCode_)
|
||||||
|
: pairIndex(pairIndex_), scriptCode(scriptCode_) {}
|
||||||
int32_t pairIndex = 0;
|
int32_t pairIndex = 0;
|
||||||
UScriptCode scriptCode = USCRIPT_INVALID_CODE;
|
UScriptCode scriptCode = USCRIPT_INVALID_CODE;
|
||||||
};
|
};
|
||||||
|
@ -88,7 +90,7 @@ private:
|
||||||
int32_t scriptEnd;
|
int32_t scriptEnd;
|
||||||
UScriptCode scriptCode;
|
UScriptCode scriptCode;
|
||||||
|
|
||||||
ParenStackEntry parenStack[STACK_SIZE];
|
std::vector<ParenStackEntry> parenStack;
|
||||||
int32_t parenSP;
|
int32_t parenSP;
|
||||||
|
|
||||||
static int8_t highBit(int32_t value);
|
static int8_t highBit(int32_t value);
|
||||||
|
@ -108,16 +110,19 @@ private:
|
||||||
|
|
||||||
inline ScriptRun::ScriptRun()
|
inline ScriptRun::ScriptRun()
|
||||||
{
|
{
|
||||||
|
parenStack.reserve(STACK_SIZE);
|
||||||
reset(nullptr, 0, 0);
|
reset(nullptr, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ScriptRun::ScriptRun(const UChar chars[], int32_t length)
|
inline ScriptRun::ScriptRun(const UChar chars[], int32_t length)
|
||||||
{
|
{
|
||||||
|
parenStack.reserve(STACK_SIZE);
|
||||||
reset(chars, 0, length);
|
reset(chars, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length)
|
inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length)
|
||||||
{
|
{
|
||||||
|
parenStack.reserve(STACK_SIZE);
|
||||||
reset(chars, start, length);
|
reset(chars, start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
#include <mapnik/text/scrptrun.hpp>
|
#include <mapnik/text/scrptrun.hpp>
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
template <class T, std::size_t N>
|
template <class T, std::size_t N>
|
||||||
constexpr std::size_t ARRAY_SIZE(const T (&array)[N]) noexcept
|
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.
|
// characters above it on the stack will be poped.
|
||||||
if (pairIndex >= 0) {
|
if (pairIndex >= 0) {
|
||||||
if ((pairIndex & 1) == 0) {
|
if ((pairIndex & 1) == 0) {
|
||||||
parenSP = (parenSP + 1) & STACK_MASK; // avoid out-of-bounds access
|
++parenSP;
|
||||||
parenStack[parenSP].pairIndex = pairIndex;
|
parenStack.emplace_back(pairIndex, scriptCode);
|
||||||
parenStack[parenSP].scriptCode = scriptCode;
|
|
||||||
} else if (parenSP >= 0) {
|
} else if (parenSP >= 0) {
|
||||||
int32_t pi = pairIndex & ~1;
|
int32_t pi = pairIndex & ~1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue