From 65b62d2d5c229f0847a3073a72167674e7d23a26 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 9 Feb 2022 07:51:12 +0100 Subject: QPageSize: pack StandardPageSize struct On most platforms, the old struct had a padding hole before the FP members, as well as after the character array. By packing the integer members into bit fields, we compress five ints incl. the padding hole (24 bytes) into 64 bits w/o padding (8 bytes). The size of the struct shrinks from 80 to 64 bytes, saving almost 2KiB in TEXT size. Four bytes of tail padding remain, and are available to grow the character array in the future. More compactification could be had by changing the FP members (either by turning them into floats and/or by making them a union over {mm, in}, because one can be calculated from the other), but these are for another patch, because they change return values. Pick-to: 6.3 6.2 Change-Id: I0e7f354a0341e94e9a9401a7d3b4529a8ff20a3d Reviewed-by: Thiago Macieira --- src/gui/painting/qpagesize.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qpagesize.cpp b/src/gui/painting/qpagesize.cpp index f69031df8b..5f4c87a106 100644 --- a/src/gui/painting/qpagesize.cpp +++ b/src/gui/painting/qpagesize.cpp @@ -224,11 +224,11 @@ static const int qt_windowsConversion[][2] = { // Standard sizes data struct StandardPageSize { - QPageSize::PageSizeId id; - int windowsId; // Windows DMPAPER value - QPageSize::Unit definitionUnits; // Standard definition size, e.g. ISO uses mm, ANSI uses inches - int widthPoints; - int heightPoints; + QPageSize::PageSizeId id : 8; + int windowsId : 16; // Windows DMPAPER value + QPageSize::Unit definitionUnits : 8; // Standard definition size, e.g. ISO uses mm, ANSI uses inches + int widthPoints : 16; + int heightPoints : 16; qreal widthMillimeters; qreal heightMillimeters; qreal widthInches; @@ -386,6 +386,7 @@ static const StandardPageSize qt_pageSizes[] = { static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0])); static_assert(pageSizesCount == QPageSize::LastPageSize + 1); +static_assert(QPageSize::LastPageSize < 256); // Return key name for PageSize static QString qt_keyForPageSizeId(QPageSize::PageSizeId id) -- cgit v1.2.3