Fix double initialization of QRgba64 with C++14
Use constructors with C++11/C++14 where it is allowed to avoid hack that caused double initialization and thereby performance regression with C++14. Change-Id: I7ae86df8aa34000b2c186e22bd9917303354b794 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
bc2dabf8ff
commit
2f43ac9dcd
@ -58,33 +58,34 @@ class QRgba64 {
|
||||
#endif
|
||||
};
|
||||
|
||||
public:
|
||||
// No constructors are allowed, since this needs to be usable in a union in no-c++11 mode.
|
||||
// When c++11 is mandatory, we can add all but a copy constructor.
|
||||
Q_DECL_RELAXED_CONSTEXPR static
|
||||
QRgba64 fromRgba64(quint16 red, quint16 green, quint16 blue, quint16 alpha)
|
||||
{
|
||||
QRgba64 rgba64
|
||||
#ifdef Q_COMPILER_UNIFORM_INIT
|
||||
= {}
|
||||
// No constructors are allowed in C++98, since this needs to be usable in a union.
|
||||
// We however require one for constexprs in C++11/C++14
|
||||
#ifdef Q_COMPILER_CONSTEXPR
|
||||
explicit Q_ALWAYS_INLINE Q_DECL_CONSTEXPR QRgba64(quint64 c) : rgba(c) { }
|
||||
#endif
|
||||
;
|
||||
rgba64.rgba = quint64(red) << RedShift
|
||||
| quint64(green) << GreenShift
|
||||
| quint64(blue) << BlueShift
|
||||
| quint64(alpha) << AlphaShift;
|
||||
return rgba64;
|
||||
}
|
||||
Q_DECL_RELAXED_CONSTEXPR static
|
||||
public:
|
||||
#ifdef Q_COMPILER_CONSTEXPR
|
||||
Q_ALWAYS_INLINE Q_DECL_CONSTEXPR QRgba64() : rgba(0) { }
|
||||
#endif
|
||||
|
||||
Q_DECL_CONSTEXPR static
|
||||
QRgba64 fromRgba64(quint64 c)
|
||||
{
|
||||
QRgba64 rgba64
|
||||
#ifdef Q_COMPILER_UNIFORM_INIT
|
||||
= {}
|
||||
#endif
|
||||
;
|
||||
#ifdef Q_COMPILER_CONSTEXPR
|
||||
return QRgba64(c);
|
||||
#else
|
||||
QRgba64 rgba64;
|
||||
rgba64.rgba = c;
|
||||
return rgba64;
|
||||
#endif
|
||||
}
|
||||
Q_DECL_CONSTEXPR static
|
||||
QRgba64 fromRgba64(quint16 red, quint16 green, quint16 blue, quint16 alpha)
|
||||
{
|
||||
return fromRgba64(quint64(red) << RedShift
|
||||
| quint64(green) << GreenShift
|
||||
| quint64(blue) << BlueShift
|
||||
| quint64(alpha) << AlphaShift);
|
||||
}
|
||||
Q_DECL_RELAXED_CONSTEXPR static QRgba64 fromRgba(quint8 red, quint8 green, quint8 blue, quint8 alpha)
|
||||
{
|
||||
@ -190,12 +191,12 @@ private:
|
||||
|
||||
Q_DECLARE_TYPEINFO(QRgba64, Q_PRIMITIVE_TYPE);
|
||||
|
||||
Q_DECL_RELAXED_CONSTEXPR inline QRgba64 qRgba64(quint16 r, quint16 g, quint16 b, quint16 a)
|
||||
Q_DECL_CONSTEXPR inline QRgba64 qRgba64(quint16 r, quint16 g, quint16 b, quint16 a)
|
||||
{
|
||||
return QRgba64::fromRgba64(r, g, b, a);
|
||||
}
|
||||
|
||||
Q_DECL_RELAXED_CONSTEXPR inline QRgba64 qRgba64(quint64 c)
|
||||
Q_DECL_CONSTEXPR inline QRgba64 qRgba64(quint64 c)
|
||||
{
|
||||
return QRgba64::fromRgba64(c);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user