summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-09-03 20:53:31 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-09-04 16:35:37 +0000
commiteffbf147a425bb7b656e23927e2f733597a5b299 (patch)
treee08a9059b3a63ca399b624914ba105fef7f55105 /util
parent90ae72d852826c9b8a80fbd1eb551dedac655c54 (diff)
downloadqtbase-effbf147a425bb7b656e23927e2f733597a5b299.tar.gz
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 <lars.knoll@qt.io>
Diffstat (limited to 'util')
-rw-r--r--util/unicode/main.cpp90
1 files changed, 30 insertions, 60 deletions
diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp
index 16f9e4be66..26cdab87d6 100644
--- a/util/unicode/main.cpp
+++ b/util/unicode/main.cpp
@@ -789,6 +789,15 @@ static void initScriptMap()
// Keep this one in sync with the code in createPropertyInfo
static const char *property_string =
+ "enum Case {\n"
+ " LowerCase,\n"
+ " UpperCase,\n"
+ " TitleCase,\n"
+ " CaseFold,\n"
+ "\n"
+ " NumCases\n"
+ "};\n"
+ "\n"
"struct Properties {\n"
" ushort category : 8; /* 5 used */\n"
" ushort direction : 8; /* 5 used */\n"
@@ -796,19 +805,15 @@ static const char *property_string =
" ushort joining : 3;\n"
" signed short digitValue : 5;\n"
" signed short mirrorDiff : 16;\n"
- " ushort lowerCaseSpecial : 1;\n"
- " signed short lowerCaseDiff : 15;\n"
+ " ushort unicodeVersion : 8; /* 5 used */\n"
+ " ushort nfQuickCheck : 8;\n" // could be narrowed
"#ifdef Q_OS_WASM\n"
" unsigned char : 0; //wasm 64 packing trick\n"
"#endif\n"
- " ushort upperCaseSpecial : 1;\n"
- " signed short upperCaseDiff : 15;\n"
- " ushort titleCaseSpecial : 1;\n"
- " signed short titleCaseDiff : 15;\n"
- " ushort caseFoldSpecial : 1;\n"
- " signed short caseFoldDiff : 15;\n"
- " ushort unicodeVersion : 8; /* 5 used */\n"
- " ushort nfQuickCheck : 8;\n" // could be narrowed
+ " struct {\n"
+ " ushort special : 1;\n"
+ " signed short diff : 15;\n"
+ " } cases[NumCases];\n"
"#ifdef Q_OS_WASM\n"
" unsigned char : 0; //wasm 64 packing trick\n"
"#endif\n"
@@ -820,38 +825,6 @@ static const char *property_string =
"};\n\n"
"Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4) noexcept;\n"
"Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2) noexcept;\n"
- "\n"
- "struct LowercaseTraits\n"
- "{\n"
- " static inline signed short caseDiff(const Properties *prop)\n"
- " { return prop->lowerCaseDiff; }\n"
- " static inline bool caseSpecial(const Properties *prop)\n"
- " { return prop->lowerCaseSpecial; }\n"
- "};\n"
- "\n"
- "struct UppercaseTraits\n"
- "{\n"
- " static inline signed short caseDiff(const Properties *prop)\n"
- " { return prop->upperCaseDiff; }\n"
- " static inline bool caseSpecial(const Properties *prop)\n"
- " { return prop->upperCaseSpecial; }\n"
- "};\n"
- "\n"
- "struct TitlecaseTraits\n"
- "{\n"
- " static inline signed short caseDiff(const Properties *prop)\n"
- " { return prop->titleCaseDiff; }\n"
- " static inline bool caseSpecial(const Properties *prop)\n"
- " { return prop->titleCaseSpecial; }\n"
- "};\n"
- "\n"
- "struct CasefoldTraits\n"
- "{\n"
- " static inline signed short caseDiff(const Properties *prop)\n"
- " { return prop->caseFoldDiff; }\n"
- " static inline bool caseSpecial(const Properties *prop)\n"
- " { return prop->caseFoldSpecial; }\n"
- "};\n"
"\n";
static const char *methods =
@@ -2473,36 +2446,33 @@ static QByteArray createPropertyInfo()
// " signed short mirrorDiff : 16;\n"
out += QByteArray::number( p.mirrorDiff );
out += ", ";
-// " ushort lowerCaseSpecial : 1;\n"
-// " signed short lowerCaseDiff : 15;\n"
+// " ushort unicodeVersion : 8; /* 5 used */\n"
+ out += QByteArray::number( p.age );
+ out += ", ";
+// " ushort nfQuickCheck : 8;\n"
+ out += QByteArray::number( p.nfQuickCheck );
+ out += ", ";
+// " struct {\n"
+// " ushort special : 1;\n"
+// " signed short diff : 15;\n"
+// " } cases[NumCases];\n"
+ out += " { {";
out += QByteArray::number( p.lowerCaseSpecial );
out += ", ";
out += QByteArray::number( p.lowerCaseDiff );
- out += ", ";
-// " ushort upperCaseSpecial : 1;\n"
-// " signed short upperCaseDiff : 15;\n"
+ out += "}, {";
out += QByteArray::number( p.upperCaseSpecial );
out += ", ";
out += QByteArray::number( p.upperCaseDiff );
- out += ", ";
-// " ushort titleCaseSpecial : 1;\n"
-// " signed short titleCaseDiff : 15;\n"
+ out += "}, {";
out += QByteArray::number( p.titleCaseSpecial );
out += ", ";
out += QByteArray::number( p.titleCaseDiff );
- out += ", ";
-// " ushort caseFoldSpecial : 1;\n"
-// " signed short caseFoldDiff : 15;\n"
+ out += "}, {";
out += QByteArray::number( p.caseFoldSpecial );
out += ", ";
out += QByteArray::number( p.caseFoldDiff );
- out += ", ";
-// " ushort unicodeVersion : 8; /* 5 used */\n"
- out += QByteArray::number( p.age );
- out += ", ";
-// " ushort nfQuickCheck : 8;\n"
- out += QByteArray::number( p.nfQuickCheck );
- out += ", ";
+ out += "} }, ";
// " ushort graphemeBreakClass : 5; /* 5 used */\n"
// " ushort wordBreakClass : 5; /* 5 used */\n"
// " ushort lineBreakClass : 6; /* 6 used */\n"