From 2737b5e36a55d9fac78d5339ce4f4f87f8c9a8a6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 3 Sep 2019 23:40:56 +0200 Subject: QUnicodeTables: pack Properties struct GCC doesn't like the sequence : 5 : 5 : 8 : 6 : 8 and inserts a :6 padding between the :5 and the :8 and a :2 padding between the :6 and the :8, growing the bitfield by 8 bits of embedded padding and another byte to bring the struct back to sizeof % 2 == 0. Fix by reshuffling the elements and adding a static_assert for the next round. Saves ~5KiB in QtCore executable size. Change-Id: I4758a6f48ba389abc2aee92f60997d42ebb0e5b8 Reviewed-by: Thiago Macieira --- src/corelib/text/qunicodetables_p.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/corelib/text/qunicodetables_p.h') diff --git a/src/corelib/text/qunicodetables_p.h b/src/corelib/text/qunicodetables_p.h index cb7a211cb6..d54075d274 100644 --- a/src/corelib/text/qunicodetables_p.h +++ b/src/corelib/text/qunicodetables_p.h @@ -88,8 +88,8 @@ struct Properties { #endif ushort graphemeBreakClass : 5; /* 5 used */ ushort wordBreakClass : 5; /* 5 used */ - ushort sentenceBreakClass : 8; /* 4 used */ ushort lineBreakClass : 6; /* 6 used */ + ushort sentenceBreakClass : 8; /* 4 used */ ushort script : 8; }; @@ -128,6 +128,8 @@ struct CasefoldTraits { return prop->caseFoldSpecial; } }; +Q_STATIC_ASSERT(sizeof(Properties) == 20); + enum GraphemeBreakClass { GraphemeBreak_Any, GraphemeBreak_CR, -- cgit v1.2.3 From effbf147a425bb7b656e23927e2f733597a5b299 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 3 Sep 2019 20:53:31 +0200 Subject: QUnicodeTables: use array for case folding tables Instead of four pairs of :1 :15 bit fields, use an array of four :1, :15 structs. This allows to replace the case folding traits classes with a simple enum that indexes into said array. I don't know what the WASM #ifdef'ed code is supposed to effect (a :0 bit-field is only useful to separate adjacent bit-field into separate memory locations for multi-threading), but I thought it safer to leave it in, and that means the array must be a 64-bit block of its own, so I had to move two fields around. Saves ~4.5KiB in text size on optimized GCC 10 LTO Linux AMD64 builds. Change-Id: Ib52cd7706342d5227b50b57545d073829c45da9a Reviewed-by: Lars Knoll --- src/corelib/text/qunicodetables_p.h | 57 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) (limited to 'src/corelib/text/qunicodetables_p.h') diff --git a/src/corelib/text/qunicodetables_p.h b/src/corelib/text/qunicodetables_p.h index d54075d274..c453ef53e7 100644 --- a/src/corelib/text/qunicodetables_p.h +++ b/src/corelib/text/qunicodetables_p.h @@ -63,6 +63,15 @@ QT_BEGIN_NAMESPACE namespace QUnicodeTables { +enum Case { + LowerCase, + UpperCase, + TitleCase, + CaseFold, + + NumCases +}; + struct Properties { ushort category : 8; /* 5 used */ ushort direction : 8; /* 5 used */ @@ -70,19 +79,15 @@ struct Properties { ushort joining : 3; signed short digitValue : 5; signed short mirrorDiff : 16; - ushort lowerCaseSpecial : 1; - signed short lowerCaseDiff : 15; + ushort unicodeVersion : 8; /* 5 used */ + ushort nfQuickCheck : 8; #ifdef Q_OS_WASM unsigned char : 0; //wasm 64 packing trick #endif - ushort upperCaseSpecial : 1; - signed short upperCaseDiff : 15; - ushort titleCaseSpecial : 1; - signed short titleCaseDiff : 15; - ushort caseFoldSpecial : 1; - signed short caseFoldDiff : 15; - ushort unicodeVersion : 8; /* 5 used */ - ushort nfQuickCheck : 8; + struct { + ushort special : 1; + signed short diff : 15; + } cases[NumCases]; #ifdef Q_OS_WASM unsigned char : 0; //wasm 64 packing trick #endif @@ -96,38 +101,6 @@ struct Properties { Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept; Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept; -struct LowercaseTraits -{ - static inline signed short caseDiff(const Properties *prop) - { return prop->lowerCaseDiff; } - static inline bool caseSpecial(const Properties *prop) - { return prop->lowerCaseSpecial; } -}; - -struct UppercaseTraits -{ - static inline signed short caseDiff(const Properties *prop) - { return prop->upperCaseDiff; } - static inline bool caseSpecial(const Properties *prop) - { return prop->upperCaseSpecial; } -}; - -struct TitlecaseTraits -{ - static inline signed short caseDiff(const Properties *prop) - { return prop->titleCaseDiff; } - static inline bool caseSpecial(const Properties *prop) - { return prop->titleCaseSpecial; } -}; - -struct CasefoldTraits -{ - static inline signed short caseDiff(const Properties *prop) - { return prop->caseFoldDiff; } - static inline bool caseSpecial(const Properties *prop) - { return prop->caseFoldSpecial; } -}; - Q_STATIC_ASSERT(sizeof(Properties) == 20); enum GraphemeBreakClass { -- cgit v1.2.3