diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-14 01:26:25 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-02-15 20:14:27 +0000 |
commit | 04d6495bf773a6bb0d4fa6980df22d3b81a605b0 (patch) | |
tree | 3372ff44c12f502402f80704c058082d1d27257b /src/gui/image | |
parent | a5febadac55741b4b48f25463a310835cc8bde19 (diff) |
Make some atomic counters zero-based
A variable of static storage duration that is not zero-initialized
takes up space in the DATA segment of the executable. By making the
counters start at zero and adding the initial value afterwards, we
move them over to the BSS segment, which does not take up space in
the executable.
Wrap atomics used across function boundaries into small functions,
to avoid code duplication and to increase readability.
Change-Id: Ida6ed316ecb8fe20da62a9577161349e14de5aed
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qicon.cpp | 8 | ||||
-rw-r--r-- | src/gui/image/qimage.cpp | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 17734f05f3..0c3323636a 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -97,7 +97,11 @@ QT_BEGIN_NAMESPACE \value On Display the pixmap when the widget is in an "on" state */ -static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1); +static int nextSerialNumCounter() +{ + static QBasicAtomicInt serial; + return 1 + serial.fetchAndAddRelaxed(1); +} static void qt_cleanup_icon_cache(); namespace { @@ -139,7 +143,7 @@ static qreal qt_effective_device_pixel_ratio(QWindow *window = 0) QIconPrivate::QIconPrivate(QIconEngine *e) : engine(e), ref(1), - serialNum(serialNumCounter.fetchAndAddRelaxed(1)), + serialNum(nextSerialNumCounter()), detach_no(0), is_mask(false) { diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 9870e19cec..75229ada6c 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -89,12 +89,16 @@ static QImage rotated90(const QImage &src); static QImage rotated180(const QImage &src); static QImage rotated270(const QImage &src); -QBasicAtomicInt qimage_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1); +static int next_qimage_serial_number() +{ + static QBasicAtomicInt serial; + return 1 + serial.fetchAndAddRelaxed(1); +} QImageData::QImageData() : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(0), format(QImage::Format_ARGB32), bytes_per_line(0), - ser_no(qimage_serial_number.fetchAndAddRelaxed(1)), + ser_no(next_qimage_serial_number()), detach_no(0), dpmx(qt_defaultDpiX() * 100 / qreal(2.54)), dpmy(qt_defaultDpiY() * 100 / qreal(2.54)), |