diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-20 14:58:03 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-01 12:36:42 +0000 |
commit | f3dd2e8cc0d913acaa9046990978a1e8ed02e472 (patch) | |
tree | a1f582bdfb972589c8e2f53f9602511ac939e042 | |
parent | e3398e3589e08a58b0617a09619a8ea40a40d3f5 (diff) |
CangjieTable: thoroughly QStringView-enable
Nothing in the implementation of CangjieTable needs QString. This is
all very basic parsing. So use QStringView. Now all operations are
free of dynamic memory allocations.
Change-Id: I353bab484ef6d551e03c7d8bb04e7e1a923f830e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/plugins/tcime/3rdparty/tcime/cangjietable.cpp | 14 | ||||
-rw-r--r-- | src/plugins/tcime/3rdparty/tcime/cangjietable.h | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/plugins/tcime/3rdparty/tcime/cangjietable.cpp b/src/plugins/tcime/3rdparty/tcime/cangjietable.cpp index 47fd2383..cb43cfac 100644 --- a/src/plugins/tcime/3rdparty/tcime/cangjietable.cpp +++ b/src/plugins/tcime/3rdparty/tcime/cangjietable.cpp @@ -33,18 +33,18 @@ static Q_CONSTEXPR char16_t letters[] = u"\x65e5\x6708\x91d1\x6728\x6c34\x706b\x571f\x7af9\x6208\x5341\x5927\x4e2d\x4e00\x5f13" u"\x4eba\x5fc3\x624b\x53e3\x5c38\x5eff\x5c71\x5973\x7530\x96e3\x535c"; -bool CangjieTable::isLetter(const QChar &c) +bool CangjieTable::isLetter(QChar c) { return QStringView(letters).contains(c); } -int CangjieTable::getPrimaryIndex(const QString &code) +int CangjieTable::getPrimaryIndex(QStringView code) { - int length = code.length(); + const qsizetype length = code.size(); if ((length < 1) || (length > MAX_CODE_LENGTH)) return -1; - QChar c = code.at(0); + QChar c = code.front(); if (!isLetter(c)) return -1; @@ -54,17 +54,17 @@ int CangjieTable::getPrimaryIndex(const QString &code) if (length < 2) return index; - c = code.at(length - 1); + c = code.back(); if (!isLetter(c)) return -1; return index + QStringView(letters).indexOf(c) + 1; } -int CangjieTable::getSecondaryIndex(const QString &code) +int CangjieTable::getSecondaryIndex(QStringView code) { int index = 0; - int last = code.length() - 1; + const qsizetype last = code.size() - 1; for (int i = 1; i < last; i++) { QChar c = code.at(i); if (!isLetter(c)) diff --git a/src/plugins/tcime/3rdparty/tcime/cangjietable.h b/src/plugins/tcime/3rdparty/tcime/cangjietable.h index 9d37012a..223caa0a 100644 --- a/src/plugins/tcime/3rdparty/tcime/cangjietable.h +++ b/src/plugins/tcime/3rdparty/tcime/cangjietable.h @@ -47,7 +47,7 @@ public: /** * Returns {@code true} only if the given character is a valid cangjie letter. */ - static bool isLetter(const QChar &c); + static bool isLetter(QChar c); /** * Returns the primary index calculated by the first and last letter of @@ -56,7 +56,7 @@ public: * @param code should not be null. * @return -1 for invalid code. */ - static int getPrimaryIndex(const QString &code); + static int getPrimaryIndex(QStringView code); /** * Returns the secondary index calculated by letters between the first and @@ -65,7 +65,7 @@ public: * @param code should not be null. * @return -1 for invalid code. */ - static int getSecondaryIndex(const QString &code); + static int getSecondaryIndex(QStringView code); }; } |