Improve data member ordering and initialization in some private classes

Put bit fields together, and generally order by size to maximize the
compiler's ability to pack data. Initialize in declaration where
possible.

Change-Id: I49d4a3d2271229d671aeaf3eb17e6b7ecdc5099e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Volker Hilsheimer 2020-07-02 16:50:24 +02:00
parent ae890390e5
commit a10bf2ec5a
3 changed files with 66 additions and 93 deletions

View File

@ -755,22 +755,12 @@ void QPlainTextEditPrivate::updateViewport()
}
QPlainTextEditPrivate::QPlainTextEditPrivate()
: control(nullptr),
tabChangesFocus(false),
lineWrap(QPlainTextEdit::WidgetWidth),
wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere),
keyboardModifiers{},
clickCausedFocus(0), placeholderVisible(1),
topLine(0), topLineFracture(0),
: tabChangesFocus(false), showCursorOnInitialShow(false), backgroundVisible(false),
centerOnScroll(false), inDrag(false), clickCausedFocus(false), placeholderVisible(true),
pageUpDownLastCursorYIsValid(false)
{
showCursorOnInitialShow = true;
backgroundVisible = false;
centerOnScroll = false;
inDrag = false;
}
void QPlainTextEditPrivate::init(const QString &txt)
{
Q_Q(QPlainTextEdit);
@ -825,7 +815,6 @@ void QPlainTextEditPrivate::init(const QString &txt)
#ifndef QT_NO_CURSOR
viewport->setCursor(Qt::IBeamCursor);
#endif
originalOffsetY = 0;
}
void QPlainTextEditPrivate::_q_textChanged()

View File

@ -143,26 +143,30 @@ public:
void updateDefaultTextOption();
QPlainTextEditControl *control;
bool tabChangesFocus;
QBasicTimer autoScrollTimer;
#ifdef QT_KEYPAD_NAVIGATION
QBasicTimer deleteAllTimer;
#endif
QPoint autoScrollDragPos;
QString placeholderText;
QPlainTextEdit::LineWrapMode lineWrap;
QTextOption::WrapMode wordWrap;
Qt::KeyboardModifiers keyboardModifiers;
QPlainTextEditControl *control = nullptr;
qreal topLineFracture = 0; // for non-int sized fonts
qreal pageUpDownLastCursorY = 0;
QPlainTextEdit::LineWrapMode lineWrap = QPlainTextEdit::WidgetWidth;
QTextOption::WrapMode wordWrap = QTextOption::WrapAtWordBoundaryOrAnywhere;
Qt::KeyboardModifiers keyboardModifiers = {};
int originalOffsetY = 0;
int topLine = 0;
uint tabChangesFocus : 1;
uint showCursorOnInitialShow : 1;
uint backgroundVisible : 1;
uint centerOnScroll : 1;
uint inDrag : 1;
uint clickCausedFocus : 1;
uint placeholderVisible : 1;
int topLine;
qreal topLineFracture; // for non-int sized fonts
uint pageUpDownLastCursorYIsValid : 1;
void setTopLine(int visualTopLine, int dx = 0);
void setTopBlock(int newTopBlock, int newTopLine, int dx = 0);
@ -175,19 +179,8 @@ public:
void append(const QString &text, Qt::TextFormat format = Qt::AutoText);
qreal pageUpDownLastCursorY;
bool pageUpDownLastCursorYIsValid;
#ifdef QT_KEYPAD_NAVIGATION
QBasicTimer deleteAllTimer;
#endif
void _q_cursorPositionChanged();
void _q_modificationChanged(bool);
int originalOffsetY;
QString placeholderText;
};
QT_END_NAMESPACE

View File

@ -88,43 +88,60 @@ class Q_WIDGETS_EXPORT QTabBarPrivate : public QWidgetPrivate
Q_DECLARE_PUBLIC(QTabBar)
public:
QTabBarPrivate()
: currentIndex(-1), mouseButtons(Qt::NoButton), pressedIndex(-1), firstVisible(0), lastVisible(-1),
shape(QTabBar::RoundedNorth), layoutDirty(false), drawBase(true), scrollOffset(0),
hoverIndex(-1), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true),
closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab),
paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false),
autoHide(false), changeCurrentOnDrag(false), switchTabCurrentIndex(-1), switchTabTimerId(0),
movingTab(nullptr)
{}
: layoutDirty(false), drawBase(true), elideModeSetByUser(false), useScrollButtons(false),
useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false),
paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false),
autoHide(false), changeCurrentOnDrag(false)
{}
int currentIndex;
Qt::MouseButtons mouseButtons;
int pressedIndex;
int firstVisible;
int lastVisible;
QTabBar::Shape shape;
bool layoutDirty;
bool drawBase;
int scrollOffset;
QRect hoverRect;
QPoint dragStartPosition;
QSize iconSize;
QToolButton* rightB = nullptr; // right or bottom
QToolButton* leftB = nullptr; // left or top
QMovableTabWidget *movingTab = nullptr;
int hoverIndex = -1;
int switchTabCurrentIndex = -1;
int switchTabTimerId = 0;
Qt::TextElideMode elideMode = Qt::ElideNone;
QTabBar::SelectionBehavior selectionBehaviorOnRemove = QTabBar::SelectRightTab;
QTabBar::Shape shape = QTabBar::RoundedNorth;
Qt::MouseButtons mouseButtons = Qt::NoButton;
int currentIndex = -1;
int pressedIndex = -1;
int firstVisible = 0;
int lastVisible = -1;
int scrollOffset = 0;
bool layoutDirty : 1;
bool drawBase : 1;
bool elideModeSetByUser : 1;
bool useScrollButtons : 1;
bool useScrollButtonsSetByUser : 1;
bool expanding : 1;
bool closeButtonOnTabs : 1;
bool paintWithOffsets : 1;
bool movable : 1;
bool dragInProgress : 1;
bool documentMode : 1;
bool autoHide : 1;
bool changeCurrentOnDrag : 1;
struct Tab {
inline Tab(const QIcon &ico, const QString &txt)
: enabled(true) , visible(true), shortcutId(0), text(txt), icon(ico),
leftWidget(nullptr), rightWidget(nullptr), lastTab(-1), dragOffset(0)
#if QT_CONFIG(animation)
, animation(nullptr)
#endif // animation
: text(txt), icon(ico), enabled(true), visible(true)
{}
bool operator==(const Tab &other) const { return &other == this; }
bool enabled;
bool visible;
int shortcutId;
QString text;
#if QT_CONFIG(tooltip)
QString toolTip;
#endif
#if QT_CONFIG(whatsthis)
QString whatsThis;
#endif
#ifndef QT_NO_ACCESSIBILITY
QString accessibleName;
#endif
QIcon icon;
QRect rect;
@ -133,13 +150,13 @@ public:
QColor textColor;
QVariant data;
QWidget *leftWidget;
QWidget *rightWidget;
int lastTab;
int dragOffset;
#ifndef QT_NO_ACCESSIBILITY
QString accessibleName;
#endif
QWidget *leftWidget = nullptr;
QWidget *rightWidget = nullptr;
int shortcutId = 0;
int lastTab = -1;
int dragOffset = 0;
uint enabled : 1;
uint visible : 1;
#if QT_CONFIG(animation)
~Tab() { delete animation; }
@ -154,7 +171,7 @@ public:
//these are needed for the callbacks
Tab *tab;
QTabBarPrivate *priv;
} *animation;
} *animation = nullptr;
void startAnimation(QTabBarPrivate *priv, int duration) {
if (!priv->isAnimated()) {
@ -191,15 +208,10 @@ public:
inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
void setCurrentNextEnabledIndex(int offset);
QToolButton* rightB; // right or bottom
QToolButton* leftB; // left or top
void _q_scrollTabs();
void _q_closeTab();
void moveTab(int index, int offset);
void moveTabFinished(int index);
QRect hoverRect;
int hoverIndex;
void refresh();
void layoutTabs();
@ -215,28 +227,7 @@ public:
void initBasicStyleOption(QStyleOptionTab *option, int tabIndex) const;
void makeVisible(int index);
QSize iconSize;
Qt::TextElideMode elideMode;
bool elideModeSetByUser;
bool useScrollButtons;
bool useScrollButtonsSetByUser;
bool expanding;
bool closeButtonOnTabs;
QTabBar::SelectionBehavior selectionBehaviorOnRemove;
QPoint dragStartPosition;
bool paintWithOffsets;
bool movable;
bool dragInProgress;
bool documentMode;
bool autoHide;
bool changeCurrentOnDrag;
int switchTabCurrentIndex;
int switchTabTimerId;
QMovableTabWidget *movingTab;
// shared by tabwidget and qtabbar
static void initStyleBaseOption(QStyleOptionTabBarBase *optTabBase, QTabBar *tabbar, QSize size)
{