From 34ef1069b0fbce552d74e86b3075fa584823e28d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 30 Mar 2020 08:09:53 +0000 Subject: [PATCH] mark some environment queries as static and const Signed-off-by: Ivailo Monev --- src/core/global/qglobal.cpp | 3 ++- src/gui/graphicsview/qgraphicslayout_p.h | 4 +--- src/gui/kernel/qapplication.cpp | 2 +- src/gui/kernel/qguiplatformplugin.cpp | 2 +- src/gui/kernel/qlayout.cpp | 5 +---- src/gui/kernel/qwidget.cpp | 6 ++---- src/gui/kernel/qwidget_x11.cpp | 2 +- src/gui/painting/qbackingstore.cpp | 14 ++++---------- 8 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/core/global/qglobal.cpp b/src/core/global/qglobal.cpp index f24d51a5b..def937427 100644 --- a/src/core/global/qglobal.cpp +++ b/src/core/global/qglobal.cpp @@ -1454,7 +1454,8 @@ void qt_message_output(QtMsgType msgType, const char *buf) fflush(stderr); } - if (msgType == QtFatalMsg || (msgType == QtWarningMsg && (!qgetenv("QT_FATAL_WARNINGS").isNull()))) + static const bool fatalwarnings = qgetenv("QT_FATAL_WARNINGS").isNull(); + if (msgType == QtFatalMsg || (msgType == QtWarningMsg && !fatalwarnings)) abort(); // trap; generates core dump } diff --git a/src/gui/graphicsview/qgraphicslayout_p.h b/src/gui/graphicsview/qgraphicslayout_p.h index 338be471b..d3c49f46a 100644 --- a/src/gui/graphicsview/qgraphicslayout_p.h +++ b/src/gui/graphicsview/qgraphicslayout_p.h @@ -63,9 +63,7 @@ class QGraphicsWidget; #ifndef QT_NO_DEBUG inline bool qt_graphicsLayoutDebug() { - static int checked_env = -1; - if(checked_env == -1) - checked_env = !!qgetenv("QT_GRAPHICSLAYOUT_DEBUG").toInt(); + static const int checked_env = !!qgetenv("QT_GRAPHICSLAYOUT_DEBUG").toInt(); return checked_env; } #endif diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 6200ef765..3f24d7832 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -1046,7 +1046,7 @@ QStyle *QApplication::style() // QString style; #ifdef QT_BUILD_INTERNAL - QString envStyle = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); + static const QString envStyle = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); #endif if (!QApplicationPrivate::styleOverride.isEmpty()) { style = QApplicationPrivate::styleOverride; diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp index 991a68bba..952c674cf 100644 --- a/src/gui/kernel/qguiplatformplugin.cpp +++ b/src/gui/kernel/qguiplatformplugin.cpp @@ -57,7 +57,7 @@ QGuiPlatformPlugin *qt_guiPlatformPlugin() { #ifndef QT_NO_LIBRARY - QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN")); + static QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN")); if (key.isEmpty()) { key = QString::fromLocal8Bit(qgetenv("DESKTOP_SESSION")); } diff --git a/src/gui/kernel/qlayout.cpp b/src/gui/kernel/qlayout.cpp index 325741a7a..d44595485 100644 --- a/src/gui/kernel/qlayout.cpp +++ b/src/gui/kernel/qlayout.cpp @@ -812,10 +812,7 @@ bool QLayout::adoptLayout(QLayout *layout) #ifndef QT_NO_DEBUG static bool layoutDebug() { - static int checked_env = -1; - if(checked_env == -1) - checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt(); - + static const int checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt(); return checked_env; } #endif diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 61e58503a..95cbfd372 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1099,10 +1099,8 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) } } - static int paintOnScreenEnv = -1; - if (paintOnScreenEnv == -1) - paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt() > 0 ? 1 : 0; - if (paintOnScreenEnv == 1) + static const int paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt(); + if (paintOnScreenEnv) setAttribute(Qt::WA_PaintOnScreen); if (QApplication::testAttribute(Qt::AA_NativeWindows)) diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp index 011dfc309..9321f252f 100644 --- a/src/gui/kernel/qwidget_x11.cpp +++ b/src/gui/kernel/qwidget_x11.cpp @@ -2531,7 +2531,7 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) QApplication::sendEvent(q, &e); } if (isResize) { - static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt(); + static const bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt(); // If we have a backing store with static contents, we have to disable the top-level // resize optimization in order to get invalidated regions for resized widgets. // The optimization discards all invalidateBuffer() calls since we're going to diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index 490d455d8..de6976690 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -74,14 +74,14 @@ static inline void qt_flush(QWidget *widget, const QRegion ®ion, QWindowSurfa Q_ASSERT(tlw); #if !defined(QT_NO_DEBUG) - static int flushUpdate = qgetenv("QT_FLUSH_UPDATE").toInt(); + static const int flushUpdate = qgetenv("QT_FLUSH_UPDATE").toInt(); if (flushUpdate > 0) QWidgetBackingStore::showYellowThing(widget, region, flushUpdate * 10, false); #endif //The performance hit by doing this should be negligible. However, be aware that //using this FPS when you have > 1 windowsurface can give you inaccurate FPS - static bool fpsDebug = qgetenv("QT_DEBUG_FPS").toInt(); + static const bool fpsDebug = qgetenv("QT_DEBUG_FPS").toInt(); if (fpsDebug) { static QTime time = QTime::currentTime(); static int frames = 0; @@ -695,10 +695,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) if (x->inTopLevelResize) return; - static int accelEnv = -1; - if (accelEnv == -1) { - accelEnv = qgetenv("QT_NO_FAST_MOVE").toInt() == 0; - } + static const int accelEnv = qgetenv("QT_NO_FAST_MOVE").toInt() == 0; QWidget *pw = q->parentWidget(); QPoint toplevelOffset = pw->mapTo(tlw, QPoint()); @@ -777,10 +774,7 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy) if (!wbs) return; - static int accelEnv = -1; - if (accelEnv == -1) { - accelEnv = qgetenv("QT_NO_FAST_SCROLL").toInt() == 0; - } + static const int accelEnv = qgetenv("QT_NO_FAST_SCROLL").toInt() == 0; QRect scrollRect = rect & clipRect(); bool overlapped = false;