Skip to content

Commit 67e9e2a

Browse files
committed
QCssParser: shrink indexOfId by half
All offsets fit into [0:255], so use uchar instead of short to store them, cutting the storage requirement of the array in half (-86 bytes). As drive-bys - make the array constexpr - fix formatting (only in touched lines) - port from explicit to implicit bounds with explicit bounds checking The latter has the advantage that we don't get value-initialized elements appended silently, cf. 5d8f815. Pick-to: 6.9 6.8 6.5 Change-Id: I336f850a586fd2fde8f62c65223f547402fbaa75 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
1 parent e62bebb commit 67e9e2a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/gui/text/qcssparser.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,14 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
249249
};
250250

251251
//Map id to strings as they appears in the 'values' array above
252-
static const short indexOfId[NumKnownValues] = { 0, 46, 54, 47, 55, 56, 63, 38, 29, 83, 84, 28, 48, 7, 76, 52,
252+
static constexpr uchar indexOfId[] = {
253+
0, 46, 54, 47, 55, 56, 63, 38, 29, 83, 84, 28, 48, 7, 76, 52,
253254
32, 68, 69, 30, 58, 74, 8, 12, 43, 65, 21, 15, 19, 20, 22, 24, 57, 27, 51, 80, 40, 4, 3, 45, 75, 18, 13,
254255
66, 16, 35, 77, 36, 78, 64, 79, 37, 67, 23, 59, 42, 6, 60, 70, 82, 10, 31, 41, 14, 39, 71, 9, 11, 5, 81,
255256
62, 25, 26, 33, 34, 2, 44, 72, 73, 53, 0, 17, 1, 61, 50, 49 };
256257

258+
static_assert(std::size(indexOfId) == size_t(NumKnownValues));
259+
257260
QString Value::toString() const
258261
{
259262
if (type == KnownIdentifier) {

0 commit comments

Comments
 (0)