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 <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-02-09 07:51:12 +01:00
parent 6586b030d1
commit 65b62d2d5c
1 changed files with 6 additions and 5 deletions

View File

@ -224,11 +224,11 @@ static const int qt_windowsConversion[][2] = {
// Standard sizes data // Standard sizes data
struct StandardPageSize { struct StandardPageSize {
QPageSize::PageSizeId id; QPageSize::PageSizeId id : 8;
int windowsId; // Windows DMPAPER value int windowsId : 16; // Windows DMPAPER value
QPageSize::Unit definitionUnits; // Standard definition size, e.g. ISO uses mm, ANSI uses inches QPageSize::Unit definitionUnits : 8; // Standard definition size, e.g. ISO uses mm, ANSI uses inches
int widthPoints; int widthPoints : 16;
int heightPoints; int heightPoints : 16;
qreal widthMillimeters; qreal widthMillimeters;
qreal heightMillimeters; qreal heightMillimeters;
qreal widthInches; qreal widthInches;
@ -386,6 +386,7 @@ static const StandardPageSize qt_pageSizes[] = {
static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0])); static const int pageSizesCount = int(sizeof(qt_pageSizes) / sizeof(qt_pageSizes[0]));
static_assert(pageSizesCount == QPageSize::LastPageSize + 1); static_assert(pageSizesCount == QPageSize::LastPageSize + 1);
static_assert(QPageSize::LastPageSize < 256);
// Return key name for PageSize // Return key name for PageSize
static QString qt_keyForPageSizeId(QPageSize::PageSizeId id) static QString qt_keyForPageSizeId(QPageSize::PageSizeId id)