summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qpalette.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-04-05 14:49:02 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-06 16:08:02 +0200
commitfa36d81bbcbe9cecaaa20922dd278f7b14fc3d3c (patch)
treeeabf9901da96802c1435c7b46667aeaaafe273ab /src/gui/kernel/qpalette.h
parentb0aa023aa2e08fb24eb1220c92bec02df3df8c90 (diff)
QPalette: add member-swap
Implemented as in other shared classes (e.g. QPen), except that I wrapped the bitfield in a union to speed up swapping. (GCC didn't manage to optimize (hand-rolled) swaps of adjacent bit field elements into an integer one, even at -O2). GCC -pedantic complains about anonymous structs, so I had to give the struct in the union a name. Change-Id: I519e1c2f88f6ae2dffed38b493991189d67073b8 Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/kernel/qpalette.h')
-rw-r--r--src/gui/kernel/qpalette.h27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h
index 96295ab5db..4b71af813b 100644
--- a/src/gui/kernel/qpalette.h
+++ b/src/gui/kernel/qpalette.h
@@ -74,11 +74,17 @@ public:
#ifdef Q_COMPILER_RVALUE_REFS
inline QPalette &operator=(QPalette &&other)
{
- resolve_mask = other.resolve_mask;
- current_group = other.current_group;
+ data.resolve_mask = other.data.resolve_mask;
+ data.current_group = other.data.current_group;
qSwap(d, other.d); return *this;
}
#endif
+
+ void swap(QPalette &other) {
+ qSwap(d, other.d);
+ qSwap(for_faster_swapping_dont_use, other.for_faster_swapping_dont_use);
+ }
+
operator QVariant() const;
// Do not change the order, the serialization format depends on it
@@ -94,8 +100,8 @@ public:
Foreground = WindowText, Background = Window
};
- inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
- inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }
+ inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(data.current_group); }
+ inline void setCurrentColorGroup(ColorGroup cg) { data.current_group = cg; }
inline const QColor &color(ColorGroup cg, ColorRole cr) const
{ return brush(cg, cr).color(); }
@@ -145,8 +151,8 @@ public:
qint64 cacheKey() const;
QPalette resolve(const QPalette &) const;
- inline uint resolve() const { return resolve_mask; }
- inline void resolve(uint mask) { resolve_mask = mask; }
+ inline uint resolve() const { return data.resolve_mask; }
+ inline void resolve(uint mask) { data.resolve_mask = mask; }
private:
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
@@ -170,8 +176,13 @@ private:
void detach();
QPalettePrivate *d;
- uint current_group : 4;
- uint resolve_mask : 28;
+ union {
+ struct {
+ uint current_group : 4;
+ uint resolve_mask : 28;
+ } data;
+ quint32 for_faster_swapping_dont_use;
+ };
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
};