diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-05-24 10:16:12 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-05-30 09:02:16 +0800 |
commit | 90158947eac748da91905f81ff7cfeeb30943348 (patch) | |
tree | e61b158f247e7390bd630cffb70d81820d374154 | |
parent | 4203902d12a6fb6eee5a3c805ab6b62329f5dc95 (diff) |
Core: make Unicode Database constexpr
Task-number: QTBUG-100485
Change-Id: I41480a34b14fd86a68a5c10b7e0f3d250e785d0f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 34c21d040766d54d959ed835bdf5464f657b7693)
-rw-r--r-- | src/corelib/text/qunicodetables.cpp | 22 | ||||
-rw-r--r-- | util/unicode/main.cpp | 22 |
2 files changed, 22 insertions, 22 deletions
diff --git a/src/corelib/text/qunicodetables.cpp b/src/corelib/text/qunicodetables.cpp index 4e0de5963a..2eae52a7a8 100644 --- a/src/corelib/text/qunicodetables.cpp +++ b/src/corelib/text/qunicodetables.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE namespace QUnicodeTables { -static const unsigned short uc_property_trie[] = { +static constexpr unsigned short uc_property_trie[] = { // [0x0..0x11000) 6256, 6288, 6320, 6352, 6384, 6416, 6448, 6480, @@ -7039,7 +7039,7 @@ static const unsigned short uc_property_trie[] = { 3170, 3170, 3170, 3170, 3170, 3170, 3163, 3163 }; -static const Properties uc_properties[] = { +static constexpr Properties uc_properties[] = { { 9, 18, 0, 0, -1, 0, 1, 3, 0, { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, 3, 0, 21, 0, 0, 2 }, { 9, 8, 0, 0, -1, 0, 1, 3, 0, { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, 3, 0, 17, 5, 0, 2 }, { 9, 7, 0, 0, -1, 0, 1, 3, 0, { {0, 0}, {0, 0}, {0, 0}, {0, 0} }, 2, 2, 37, 2, 0, 2 }, @@ -10268,7 +10268,7 @@ Q_CORE_EXPORT EastAsianWidth QT_FASTCALL eastAsianWidth(char32_t ucs4) noexcept return static_cast<EastAsianWidth>(qGetProp(ucs4)->eastAsianWidth); } -static const unsigned short specialCaseMap[] = { +static constexpr unsigned short specialCaseMap[] = { 0x0, // placeholder 0x1, 0x2c65, 0x1, 0x2c66, @@ -10575,9 +10575,9 @@ static const unsigned short specialCaseMap[] = { 0x1, 0xa64b }; -const unsigned int MaxSpecialCaseLength = 3; +constexpr unsigned int MaxSpecialCaseLength = 3; -static const unsigned short uc_decomposition_trie[] = { +static constexpr unsigned short uc_decomposition_trie[] = { // 0 - 0x3400 1548, 1548, 1548, 1548, 1548, 1548, 1548, 1548, @@ -12497,7 +12497,7 @@ static const unsigned short uc_decomposition_trie[] = { ? uc_decomposition_trie[uc_decomposition_trie[((ucs4 - 0x3400) >> 8) + 0x340] + (ucs4 & 0xff)] \ : 0xffff) -static const unsigned short uc_decomposition_map[] = { +static constexpr unsigned short uc_decomposition_map[] = { 0x103, 0x20, 0x210, 0x20, 0x308, 0x109, 0x61, 0x210, 0x20, 0x304, 0x109, 0x32, 0x109, 0x33, 0x210, 0x20, 0x301, 0x110, 0x3bc, 0x210, 0x20, 0x327, 0x109, 0x31, @@ -14321,7 +14321,7 @@ static const unsigned short uc_decomposition_map[] = { 0x9f16, 0x101, 0x9f3b, 0x201, 0xd869, 0xde00 }; -static const unsigned short uc_ligature_trie[] = { +static constexpr unsigned short uc_ligature_trie[] = { // 0 - 0x3100 631, 631, 631, 631, 631, 631, 631, 631, @@ -14751,7 +14751,7 @@ static const unsigned short uc_ligature_trie[] = { ? uc_ligature_trie[uc_ligature_trie[((ucs4 - 0x3100) >> 8) + 0x188] + (ucs4 & 0xff)] \ : 0xffff) -static const unsigned short uc_ligature_map[] = { +static constexpr unsigned short uc_ligature_map[] = { 0x54, 0x41, 0xc0, 0x45, 0xc8, 0x49, 0xcc, 0x4e, 0x1f8, 0x4f, 0xd2, 0x55, 0xd9, 0x57, 0x1e80, 0x59, 0x1ef2, 0x61, 0xe0, 0x65, 0xe8, 0x69, 0xec, 0x6e, @@ -15007,7 +15007,7 @@ struct NormalizationCorrection { int version; }; -static const NormalizationCorrection uc_normalization_corrections[] = { +static constexpr NormalizationCorrection uc_normalization_corrections[] = { { 0xf951, 0x96fb, 6 }, { 0x2f868, 0x2136a, 7 }, { 0x2f874, 0x5f33, 7 }, @@ -15019,7 +15019,7 @@ static const NormalizationCorrection uc_normalization_corrections[] = { enum { NumNormalizationCorrections = 6 }; enum { NormalizationCorrectionsVersionMax = 7 }; -static const char16_t idnaMappingData[] = { +static constexpr char16_t idnaMappingData[] = { 0x31, 0x31, 0x65e5, 0x31, 0x31, 0x6708, 0x31, 0x31, 0x70b9, 0x31, 0x32, 0x65e5, 0x31, 0x32, 0x6708, 0x31, 0x32, 0x70b9, 0x31, 0x33, 0x65e5, 0x31, 0x33, 0x70b9, 0x31, 0x34, 0x65e5, 0x31, 0x34, 0x70b9, 0x31, 0x35, 0x65e5, 0x31, 0x35, 0x70b9, @@ -15106,7 +15106,7 @@ struct IdnaMapEntry { }; static_assert(sizeof(IdnaMapEntry) == 8); -static const IdnaMapEntry idnaMap[] = { +static constexpr IdnaMapEntry idnaMap[] = { { 0xaa, 1, { 0x61, 0 } }, { 0xb2, 1, { 0x32, 0 } }, { 0xb3, 1, { 0x33, 0 } }, diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index ae20ba99b4..fb2b7bd813 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -1730,7 +1730,7 @@ static QByteArray createNormalizationCorrections() " int version;\n" "};\n\n" - "static const NormalizationCorrection uc_normalization_corrections[] = {\n"; + "static constexpr NormalizationCorrection uc_normalization_corrections[] = {\n"; int maxVersion = 0; int numCorrections = 0; @@ -2746,7 +2746,7 @@ static QByteArray createIdnaMapping() qsizetype memoryUsage = 0; QByteArray out = - "static const char16_t idnaMappingData[] = {"; + "static constexpr char16_t idnaMappingData[] = {"; int col = 0; for (auto c : idnaMappingData) { @@ -2771,7 +2771,7 @@ static QByteArray createIdnaMapping() " char16_t ucs[2]; // ucs[0] is offset if size > 2\n" "};\n" "static_assert(sizeof(IdnaMapEntry) == 8);\n\n" - "static const IdnaMapEntry idnaMap[] = {\n"; + "static constexpr IdnaMapEntry idnaMap[] = {\n"; for (auto i = idnaMappingTable.keyValueBegin(); i != idnaMappingTable.keyValueEnd(); i++) { const QString &mapping = i->second; @@ -2940,7 +2940,7 @@ static QByteArray createPropertyInfo() Q_ASSERT(blockMap.size() == BMP_END/BMP_BLOCKSIZE +(SMP_END-BMP_END)/SMP_BLOCKSIZE); // 0x1870 Q_ASSERT(blockMap.last() + blockMap.size() < (1<<(sizeof(unsigned short)*8))); - QByteArray out = "static const unsigned short uc_property_trie[] = {\n"; + QByteArray out = "static constexpr unsigned short uc_property_trie[] = {\n"; // First write the map from blockId to indices of unique blocks: out += " // [0x0..0x" + QByteArray::number(BMP_END, 16) + ")"; for (int i = 0; i < BMP_END/BMP_BLOCKSIZE; ++i) { @@ -2993,7 +2993,7 @@ static QByteArray createPropertyInfo() out.chop(2); out += "\n};\n\n"; - out += "static const Properties uc_properties[] = {"; + out += "static constexpr Properties uc_properties[] = {"; // keep in sync with the property declaration for (int i = 0; i < uniqueProperties.size(); ++i) { const PropertyFlags &p = uniqueProperties.at(i); @@ -3141,7 +3141,7 @@ static QByteArray createSpecialCaseMap() qDebug("createSpecialCaseMap:"); QByteArray out - = "static const unsigned short specialCaseMap[] = {\n" + = "static constexpr unsigned short specialCaseMap[] = {\n" " 0x0, // placeholder"; int i = 1; @@ -3157,7 +3157,7 @@ static QByteArray createSpecialCaseMap() maxN = std::max(maxN, n); } out.chop(1); - out += "\n};\n\nconst unsigned int MaxSpecialCaseLength = "; + out += "\n};\n\nconstexpr unsigned int MaxSpecialCaseLength = "; out += QByteArray::number(maxN); out += ";\n\n"; @@ -3289,7 +3289,7 @@ static QByteArray createCompositionInfo() Q_ASSERT(blockMap.last() + blockMap.size() < (1<<(sizeof(unsigned short)*8))); - QByteArray out = "static const unsigned short uc_decomposition_trie[] = {\n"; + QByteArray out = "static constexpr unsigned short uc_decomposition_trie[] = {\n"; // first write the map out += " // 0 - 0x" + QByteArray::number(BMP_END, 16); for (int i = 0; i < BMP_END/BMP_BLOCKSIZE; ++i) { @@ -3353,7 +3353,7 @@ static QByteArray createCompositionInfo() + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")] \\\n" " : 0xffff)\n\n"; - out += "static const unsigned short uc_decomposition_map[] = {"; + out += "static constexpr unsigned short uc_decomposition_map[] = {"; for (int i = 0; i < decompositions.size(); ++i) { if (!(i % 8)) { if (out.endsWith(' ')) @@ -3489,7 +3489,7 @@ static QByteArray createLigatureInfo() Q_ASSERT(blockMap.last() + blockMap.size() < (1<<(sizeof(unsigned short)*8))); - QByteArray out = "static const unsigned short uc_ligature_trie[] = {\n"; + QByteArray out = "static constexpr unsigned short uc_ligature_trie[] = {\n"; // first write the map out += " // 0 - 0x" + QByteArray::number(BMP_END, 16); for (int i = 0; i < BMP_END/BMP_BLOCKSIZE; ++i) { @@ -3553,7 +3553,7 @@ static QByteArray createLigatureInfo() + QByteArray::number(SMP_BLOCKSIZE-1, 16) + ")] \\\n" " : 0xffff)\n\n"; - out += "static const unsigned short uc_ligature_map[] = {"; + out += "static constexpr unsigned short uc_ligature_map[] = {"; for (int i = 0; i < ligatures.size(); ++i) { if (!(i % 8)) { if (out.endsWith(' ')) |