From 2cb7f28ec9351af4440d9597eb3d053809141541 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 1 Feb 2015 20:44:18 +0100 Subject: QtMiscUtils: make toHex*() constexpr Bring them into a constexpr'able form, by indexing into the string literal directly instead of into a static const char[], which is a declaration not allowed in a C++11 constexpr function, then mark the functions constexpr. Change-Id: I6b32a55bf24f85caeb980c0c855b8db0952f914c Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qtools_p.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 9efd964205..b48ed94236 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -51,16 +51,14 @@ QT_BEGIN_NAMESPACE namespace QtMiscUtils { -inline char toHexUpper(uint value) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline char toHexUpper(uint value) Q_DECL_NOTHROW { - static const char hexdigits[] = "0123456789ABCDEF"; - return hexdigits[value & 0xF]; + return "0123456789ABCDEF"[value & 0xF]; } -inline char toHexLower(uint value) Q_DECL_NOTHROW +Q_DECL_CONSTEXPR inline char toHexLower(uint value) Q_DECL_NOTHROW { - static const char hexdigits[] = "0123456789abcdef"; - return hexdigits[value & 0xF]; + return "0123456789abcdef"[value & 0xF]; } Q_DECL_CONSTEXPR inline int fromHex(uint c) Q_DECL_NOTHROW -- cgit v1.2.3