Mark all QChar static functions as [[gnu::const]]

The GCC documentation says that a const function is not allowed to read
global memory. This needs to be clarified: it's not allowed to read RW
global memory. It's fine to read read-only memory, as that is equivalent
to just pure code.

The QChar static out-of-line functions only lookup a property of the
given Unicode character and always return the same value.

The only exception is the decomposition() function, which returns a
QString and is therefore not allowed to be marked const.

Change-Id: Id36b2f84a1b8ff9db5acf1d4e59e8b3811068cff
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Thiago Macieira 2014-06-30 14:34:39 -07:00
parent 11c30f9705
commit 2fe90a61bd
4 changed files with 44 additions and 44 deletions

View File

@ -1398,7 +1398,7 @@ QChar::UnicodeVersion QChar::currentUnicodeVersion()
template <typename T>
static inline T toLowerCase_helper(T uc)
Q_DECL_CONST_FUNCTION static inline T toLowerCase_helper(T uc)
{
const QUnicodeTables::Properties *p = qGetProp(uc);
if (p->lowerCaseSpecial) {
@ -1409,7 +1409,7 @@ static inline T toLowerCase_helper(T uc)
}
template <typename T>
static inline T toUpperCase_helper(T uc)
Q_DECL_CONST_FUNCTION static inline T toUpperCase_helper(T uc)
{
const QUnicodeTables::Properties *p = qGetProp(uc);
if (p->upperCaseSpecial) {
@ -1420,7 +1420,7 @@ static inline T toUpperCase_helper(T uc)
}
template <typename T>
static inline T toTitleCase_helper(T uc)
Q_DECL_CONST_FUNCTION static inline T toTitleCase_helper(T uc)
{
const QUnicodeTables::Properties *p = qGetProp(uc);
if (p->titleCaseSpecial) {
@ -1431,7 +1431,7 @@ static inline T toTitleCase_helper(T uc)
}
template <typename T>
static inline T toCaseFolded_helper(T uc)
Q_DECL_CONST_FUNCTION static inline T toCaseFolded_helper(T uc)
{
const QUnicodeTables::Properties *p = qGetProp(uc);
if (p->caseFoldSpecial) {

View File

@ -450,50 +450,50 @@ public:
return ushort(ucs4%0x400 + 0xdc00);
}
static Category QT_FASTCALL category(uint ucs4);
static Direction QT_FASTCALL direction(uint ucs4);
static JoiningType QT_FASTCALL joiningType(uint ucs4);
static Category QT_FASTCALL category(uint ucs4) Q_DECL_CONST_FUNCTION;
static Direction QT_FASTCALL direction(uint ucs4) Q_DECL_CONST_FUNCTION;
static JoiningType QT_FASTCALL joiningType(uint ucs4) Q_DECL_CONST_FUNCTION;
#if QT_DEPRECATED_SINCE(5, 3)
QT_DEPRECATED static Joining QT_FASTCALL joining(uint ucs4);
QT_DEPRECATED static Joining QT_FASTCALL joining(uint ucs4) Q_DECL_CONST_FUNCTION;
#endif
static unsigned char QT_FASTCALL combiningClass(uint ucs4);
static unsigned char QT_FASTCALL combiningClass(uint ucs4) Q_DECL_CONST_FUNCTION;
static uint QT_FASTCALL mirroredChar(uint ucs4);
static bool QT_FASTCALL hasMirrored(uint ucs4);
static uint QT_FASTCALL mirroredChar(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL hasMirrored(uint ucs4) Q_DECL_CONST_FUNCTION;
static QString QT_FASTCALL decomposition(uint ucs4);
static Decomposition QT_FASTCALL decompositionTag(uint ucs4);
static Decomposition QT_FASTCALL decompositionTag(uint ucs4) Q_DECL_CONST_FUNCTION;
static int QT_FASTCALL digitValue(uint ucs4);
static uint QT_FASTCALL toLower(uint ucs4);
static uint QT_FASTCALL toUpper(uint ucs4);
static uint QT_FASTCALL toTitleCase(uint ucs4);
static uint QT_FASTCALL toCaseFolded(uint ucs4);
static int QT_FASTCALL digitValue(uint ucs4) Q_DECL_CONST_FUNCTION;
static uint QT_FASTCALL toLower(uint ucs4) Q_DECL_CONST_FUNCTION;
static uint QT_FASTCALL toUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
static uint QT_FASTCALL toTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
static uint QT_FASTCALL toCaseFolded(uint ucs4) Q_DECL_CONST_FUNCTION;
static Script QT_FASTCALL script(uint ucs4);
static Script QT_FASTCALL script(uint ucs4) Q_DECL_CONST_FUNCTION;
static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4);
static UnicodeVersion QT_FASTCALL unicodeVersion(uint ucs4) Q_DECL_CONST_FUNCTION;
static UnicodeVersion QT_FASTCALL currentUnicodeVersion();
static UnicodeVersion QT_FASTCALL currentUnicodeVersion() Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPrint(uint ucs4);
static inline bool isSpace(uint ucs4);
static bool QT_FASTCALL isMark(uint ucs4);
static bool QT_FASTCALL isPunct(uint ucs4);
static bool QT_FASTCALL isSymbol(uint ucs4);
static inline bool isLetter(uint ucs4);
static inline bool isNumber(uint ucs4);
static inline bool isLetterOrNumber(uint ucs4);
static inline bool isDigit(uint ucs4);
static inline bool isLower(uint ucs4);
static inline bool isUpper(uint ucs4);
static inline bool isTitleCase(uint ucs4);
static bool QT_FASTCALL isPrint(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isSpace(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isMark(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isPunct(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isSymbol(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isLetter(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isLetterOrNumber(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isDigit(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isLower(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isUpper(uint ucs4) Q_DECL_CONST_FUNCTION;
static inline bool isTitleCase(uint ucs4) Q_DECL_CONST_FUNCTION;
private:
static bool QT_FASTCALL isSpace_helper(uint ucs4);
static bool QT_FASTCALL isLetter_helper(uint ucs4);
static bool QT_FASTCALL isNumber_helper(uint ucs4);
static bool QT_FASTCALL isLetterOrNumber_helper(uint ucs4);
static bool QT_FASTCALL isSpace_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isLetter_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isNumber_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
static bool QT_FASTCALL isLetterOrNumber_helper(uint ucs4) Q_DECL_CONST_FUNCTION;
#ifdef QT_NO_CAST_FROM_ASCII
QChar(char c);

View File

@ -6920,24 +6920,24 @@ static const Properties uc_properties[] = {
{ 12, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 12, 0 }
};
static inline const Properties *qGetProp(uint ucs4)
Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4)
{
const int index = GET_PROP_INDEX(ucs4);
return uc_properties + index;
}
static inline const Properties *qGetProp(ushort ucs2)
Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2)
{
const int index = GET_PROP_INDEX_UCS2(ucs2);
return uc_properties + index;
}
Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)
Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)
{
return qGetProp(ucs4);
}
Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)
Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)
{
return qGetProp(ucs2);
}

View File

@ -2401,24 +2401,24 @@ static QByteArray createPropertyInfo()
out += "\n};\n\n";
out += "static inline const Properties *qGetProp(uint ucs4)\n"
out += "Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(uint ucs4)\n"
"{\n"
" const int index = GET_PROP_INDEX(ucs4);\n"
" return uc_properties + index;\n"
"}\n"
"\n"
"static inline const Properties *qGetProp(ushort ucs2)\n"
"Q_DECL_CONST_FUNCTION static inline const Properties *qGetProp(ushort ucs2)\n"
"{\n"
" const int index = GET_PROP_INDEX_UCS2(ucs2);\n"
" return uc_properties + index;\n"
"}\n"
"\n"
"Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)\n"
"Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(uint ucs4)\n"
"{\n"
" return qGetProp(ucs4);\n"
"}\n"
"\n"
"Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)\n"
"Q_DECL_CONST_FUNCTION Q_CORE_EXPORT const Properties * QT_FASTCALL properties(ushort ucs2)\n"
"{\n"
" return qGetProp(ucs2);\n"
"}\n\n";