Change signature of initScripts to take out pointer to a QVLA<ScriptItem>
This avoids one additional copy of data that we've been doing before. Change-Id: I3fae0ebe0cded632b41fdcf7efc01d5c7f2dc181 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
5af2016b7c
commit
76ced3f179
|
|
@ -53,23 +53,8 @@ static void init(QTextBoundaryFinder::BoundaryType type, const QChar *chars, int
|
|||
{
|
||||
const ushort *string = reinterpret_cast<const ushort *>(chars);
|
||||
|
||||
QVarLengthArray<QUnicodeTools::ScriptItem> scriptItems;
|
||||
{
|
||||
QVarLengthArray<uchar> scripts(length);
|
||||
|
||||
QUnicodeTools::initScripts(string, length, scripts.data());
|
||||
|
||||
int start = 0;
|
||||
for (int i = start + 1; i <= length; ++i) {
|
||||
if (i == length || scripts[i] != scripts[start]) {
|
||||
QUnicodeTools::ScriptItem item;
|
||||
item.position = start;
|
||||
item.script = scripts[start];
|
||||
scriptItems.append(item);
|
||||
start = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
QUnicodeTools::ScriptItemArray scriptItems;
|
||||
QUnicodeTools::initScripts(string, length, &scriptItems);
|
||||
|
||||
QUnicodeTools::CharAttributeOptions options;
|
||||
switch (type) {
|
||||
|
|
|
|||
|
|
@ -792,7 +792,7 @@ Q_CORE_EXPORT void initCharAttributes(const ushort *string, int length,
|
|||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Q_CORE_EXPORT void initScripts(const ushort *string, int length, uchar *scripts)
|
||||
Q_CORE_EXPORT void initScripts(const ushort *string, int length, ScriptItemArray *scripts)
|
||||
{
|
||||
int sor = 0;
|
||||
int eor = 0;
|
||||
|
|
@ -832,7 +832,7 @@ Q_CORE_EXPORT void initScripts(const ushort *string, int length, uchar *scripts)
|
|||
|
||||
Q_ASSERT(script > QChar::Script_Common);
|
||||
Q_ASSERT(sor < eor);
|
||||
::memset(scripts + sor, script, (eor - sor) * sizeof(uchar));
|
||||
scripts->append(ScriptItem{sor, script});
|
||||
sor = eor;
|
||||
|
||||
script = nscript;
|
||||
|
|
@ -840,7 +840,7 @@ Q_CORE_EXPORT void initScripts(const ushort *string, int length, uchar *scripts)
|
|||
|
||||
Q_ASSERT(script >= QChar::Script_Common);
|
||||
Q_ASSERT(eor == length);
|
||||
::memset(scripts + sor, script, (eor - sor) * sizeof(uchar));
|
||||
scripts->append(ScriptItem{sor, script});
|
||||
}
|
||||
|
||||
} // namespace QUnicodeTools
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include <QtCore/qchar.h>
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -71,13 +72,14 @@ Q_DECLARE_TYPEINFO(QCharAttributes, Q_PRIMITIVE_TYPE);
|
|||
|
||||
namespace QUnicodeTools {
|
||||
|
||||
// ### temporary
|
||||
struct ScriptItem
|
||||
{
|
||||
int position;
|
||||
int script;
|
||||
};
|
||||
|
||||
using ScriptItemArray = QVarLengthArray<ScriptItem, 64>;
|
||||
|
||||
} // namespace QUnicodeTools
|
||||
Q_DECLARE_TYPEINFO(QUnicodeTools::ScriptItem, Q_PRIMITIVE_TYPE);
|
||||
namespace QUnicodeTools {
|
||||
|
|
@ -101,7 +103,7 @@ Q_CORE_EXPORT void initCharAttributes(const ushort *string, int length,
|
|||
QCharAttributes *attributes, CharAttributeOptions options = DefaultOptionsCompat);
|
||||
|
||||
|
||||
Q_CORE_EXPORT void initScripts(const ushort *string, int length, uchar *scripts);
|
||||
Q_CORE_EXPORT void initScripts(const ushort *string, int length, ScriptItemArray *scripts);
|
||||
|
||||
} // namespace QUnicodeTools
|
||||
|
||||
|
|
|
|||
|
|
@ -2098,10 +2098,14 @@ void QTextEngine::itemize() const
|
|||
layoutData->hasBidi = bidi.process();
|
||||
|
||||
{
|
||||
QVarLengthArray<uchar> scripts(length);
|
||||
QUnicodeTools::initScripts(string, length, scripts.data());
|
||||
for (int i = 0; i < length; ++i)
|
||||
analysis[i].script = scripts.at(i);
|
||||
QUnicodeTools::ScriptItemArray scriptItems;
|
||||
QUnicodeTools::initScripts(string, length, &scriptItems);
|
||||
for (int i = 0; i < scriptItems.length(); ++i) {
|
||||
const auto &item = scriptItems.at(i);
|
||||
int end = i < scriptItems.length() - 1 ? scriptItems.at(i + 1).position : length;
|
||||
for (int j = item.position; j < end; ++j)
|
||||
analysis[j].script = item.script;
|
||||
}
|
||||
}
|
||||
|
||||
const ushort *uc = string;
|
||||
|
|
|
|||
Loading…
Reference in New Issue