QPlatformFontDatabase: compress an array of ushorts

First, all values in the array fit into 8-bit, so change the type
from ushort to quint8.

Then, instead of appending a zero as end marker, statically
determine the size of the array and use that number.

Also fixes (benign) off-by-one error in the existing reserve()
call.

Change-Id: Id05b6a56b55d2e0769b00496a55808bb7351b084
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-06-26 12:59:51 +02:00
parent 0b43c0a743
commit 2c235303c2

View File

@ -40,6 +40,9 @@
#include <QtCore/QLibraryInfo>
#include <QtCore/QDir>
#include <algorithm>
#include <iterator>
QT_BEGIN_NAMESPACE
void qt_registerFont(const QString &familyname, const QString &stylename,
@ -452,11 +455,11 @@ bool QPlatformFontDatabase::fontsAlwaysScalable() const
QList<int> QPlatformFontDatabase::standardSizes() const
{
QList<int> ret;
static const unsigned short standard[] =
{ 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 };
ret.reserve(int(sizeof(standard) / sizeof(standard[0])));
const unsigned short *sizes = standard;
while (*sizes) ret << *sizes++;
static const quint8 standard[] =
{ 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
static const int num_standards = int(sizeof standard / sizeof *standard);
ret.reserve(num_standards);
std::copy(standard, standard + num_standards, std::back_inserter(ret));
return ret;
}