From 9fc0965d1930b32277dd3845cb94b650aec67ac8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 29 Sep 2013 18:07:23 -0700 Subject: Repack structs with more than one padding hole Sizes gained (measured on 64-bit systems) BezierEase: shrunk 8 bytes QRegExpCharClass: shrunk 8 bytes QRegularExpressionPrivate: shrunk 8 bytes QTimeLinePrivate: shrunk 8 bytes QUtcTimeZonePrivate: shrunk 8 bytes QTextStreamPrivate: shrunk 8 bytes QDirPrivate: shrunk 8 bytes QFileDevicePrivate: shrunk 8 bytes Not done: QRegExpEngine: 18 bytes in 6 holes (you deserve high memory usage if you're still using QRegExp) QTextBoundaryFinder: 8 bytes in 2 holes (public class) QIODevicePrivate: 6 bytes in 2 holes, but there's no gain in packing QProcessPrivate: too complex and my copy is modified QThreadData: awaiting change from Marc Change-Id: I2a388b5ce17dec0dafcef18ed2e80d0379aa7d1e Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 4 +- src/corelib/io/qdir_p.h | 8 ++-- src/corelib/io/qfiledevice.cpp | 6 +-- src/corelib/io/qfiledevice_p.h | 13 ++++--- src/corelib/io/qtextstream_p.h | 63 +++++++++++++++++--------------- src/corelib/tools/qeasingcurve.cpp | 8 ++-- src/corelib/tools/qregexp.cpp | 4 +- src/corelib/tools/qregularexpression.cpp | 7 ++-- src/corelib/tools/qtimeline.cpp | 10 +++-- src/corelib/tools/qtimezoneprivate.cpp | 8 ++-- src/corelib/tools/qtimezoneprivate_p.h | 4 +- 11 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index db27bed9d6..43db2ec1fe 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -85,10 +85,10 @@ static QString driveSpec(const QString &path) //************* QDirPrivate QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_) : QSharedData() + , fileListsInitialized(false) , nameFilters(nameFilters_) , sort(sort_) , filters(filters_) - , fileListsInitialized(false) { setPath(path.isEmpty() ? QString::fromLatin1(".") : path); @@ -108,10 +108,10 @@ QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, Q QDirPrivate::QDirPrivate(const QDirPrivate ©) : QSharedData(copy) + , fileListsInitialized(false) , nameFilters(copy.nameFilters) , sort(copy.sort) , filters(copy.filters) - , fileListsInitialized(false) , dirEntry(copy.dirEntry) , metaData(copy.metaData) { diff --git a/src/corelib/io/qdir_p.h b/src/corelib/io/qdir_p.h index efcac439cd..bf7726db2f 100644 --- a/src/corelib/io/qdir_p.h +++ b/src/corelib/io/qdir_p.h @@ -73,16 +73,16 @@ public: void resolveAbsoluteEntry() const; + mutable bool fileListsInitialized; + mutable QStringList files; + mutable QFileInfoList fileInfos; + QStringList nameFilters; QDir::SortFlags sort; QDir::Filters filters; QScopedPointer fileEngine; - mutable bool fileListsInitialized; - mutable QStringList files; - mutable QFileInfoList fileInfos; - QFileSystemEntry dirEntry; mutable QFileSystemEntry absoluteDirEntry; mutable QFileSystemMetaData metaData; diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index f25933816a..d2c8d37d4a 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -53,9 +53,9 @@ QT_BEGIN_NAMESPACE static const int QFILE_WRITEBUFFER_SIZE = 16384; QFileDevicePrivate::QFileDevicePrivate() - : fileEngine(0), lastWasWrite(false), - writeBuffer(QFILE_WRITEBUFFER_SIZE), error(QFile::NoError), - cachedSize(0) + : fileEngine(0), + writeBuffer(QFILE_WRITEBUFFER_SIZE), cachedSize(0), + error(QFile::NoError), lastWasWrite(false) { } diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h index 4c9cf7b627..79d8427c0d 100644 --- a/src/corelib/io/qfiledevice_p.h +++ b/src/corelib/io/qfiledevice_p.h @@ -70,21 +70,22 @@ protected: virtual QAbstractFileEngine *engine() const; - QFileDevice::FileHandleFlags handleFlags; - - mutable QAbstractFileEngine *fileEngine; - bool lastWasWrite; - QRingBuffer writeBuffer; inline bool ensureFlushed() const; bool putCharHelper(char c); - QFileDevice::FileError error; void setError(QFileDevice::FileError err); void setError(QFileDevice::FileError err, const QString &errorString); void setError(QFileDevice::FileError err, int errNum); + mutable QAbstractFileEngine *fileEngine; + QRingBuffer writeBuffer; mutable qint64 cachedSize; + + QFileDevice::FileHandleFlags handleFlags; + QFileDevice::FileError error; + + bool lastWasWrite; }; inline bool QFileDevicePrivate::ensureFlushed() const diff --git a/src/corelib/io/qtextstream_p.h b/src/corelib/io/qtextstream_p.h index d5d5288426..ac6529e195 100644 --- a/src/corelib/io/qtextstream_p.h +++ b/src/corelib/io/qtextstream_p.h @@ -88,6 +88,21 @@ class QTextStreamPrivate { Q_DECLARE_PUBLIC(QTextStream) public: + // streaming parameters + class Params + { + public: + void reset(); + + int realNumberPrecision; + int integerBase; + int fieldWidth; + QChar padChar; + QTextStream::FieldAlignment fieldAlignment; + QTextStream::RealNumberNotation realNumberNotation; + QTextStream::NumberFlags numberFlags; + }; + QTextStreamPrivate(QTextStream *q_ptr); ~QTextStreamPrivate(); void reset(); @@ -97,7 +112,6 @@ public: #ifndef QT_NO_QOBJECT QDeviceClosedNotifier deviceClosedNotifier; #endif - bool deleteDevice; // string QString *string; @@ -110,6 +124,24 @@ public: QTextCodec::ConverterState readConverterState; QTextCodec::ConverterState writeConverterState; QTextCodec::ConverterState *readConverterSavedState; +#endif + + QString writeBuffer; + QString readBuffer; + int readBufferOffset; + int readConverterSavedStateOffset; //the offset between readBufferStartDevicePos and that start of the buffer + qint64 readBufferStartDevicePos; + + Params params; + + // status + QTextStream::Status status; + QLocale locale; + QTextStream *q_ptr; + + int lastTokenSize; + bool deleteDevice; +#ifndef QT_NO_TEXTCODEC bool autoDetectUnicode; #endif @@ -128,7 +160,6 @@ public: inline void consume(int nchars); void saveConverterState(qint64 newPos); void restoreToSavedConverterState(); - int lastTokenSize; // Return value type for getNumber() enum NumberParsingStatus { @@ -150,34 +181,6 @@ public: bool fillReadBuffer(qint64 maxBytes = -1); void resetReadBuffer(); void flushWriteBuffer(); - QString writeBuffer; - QString readBuffer; - int readBufferOffset; - int readConverterSavedStateOffset; //the offset between readBufferStartDevicePos and that start of the buffer - qint64 readBufferStartDevicePos; - - // streaming parameters - class Params - { - public: - void reset(); - - int realNumberPrecision; - int integerBase; - int fieldWidth; - QChar padChar; - QTextStream::FieldAlignment fieldAlignment; - QTextStream::RealNumberNotation realNumberNotation; - QTextStream::NumberFlags numberFlags; - }; - Params params; - - // status - QTextStream::Status status; - - QLocale locale; - - QTextStream *q_ptr; }; QT_END_NAMESPACE diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 5daf067c71..2708901866 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -432,14 +432,14 @@ struct BezierEase : public QEasingCurveFunction qreal p3x, p3y; }; - bool _init; - bool _valid; QVector _curves; - int _curveCount; QVector _intervals; + int _curveCount; + bool _init; + bool _valid; BezierEase() - : QEasingCurveFunction(InOut), _init(false), _valid(false), _curves(10), _intervals(10) + : QEasingCurveFunction(InOut), _curves(10), _intervals(10), _init(false), _valid(false) { } void init() diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 88499ad9d9..d2b5adc974 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1045,12 +1045,12 @@ public: #endif private: - uint c; // character classes QVector r; // character ranges - bool n; // negative? #ifndef QT_NO_REGEXP_OPTIM QVector occ1; // first-occurrence array #endif + uint c; // character classes + bool n; // negative? }; #else struct QRegExpCharClass diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index d5bd1dff00..e1cf82bb8c 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -813,8 +813,9 @@ struct QRegularExpressionPrivate : QSharedData int captureIndexForName(const QString &name) const; - QString pattern; + // sizeof(QSharedData) == 4, so start our members with an enum QRegularExpression::PatternOptions patternOptions; + QString pattern; // *All* of the following members are set managed while holding this mutex, // except for isDirty which is set to true by QRegularExpression setters @@ -889,7 +890,7 @@ QRegularExpression::QRegularExpression(QRegularExpressionPrivate &dd) \internal */ QRegularExpressionPrivate::QRegularExpressionPrivate() - : pattern(), patternOptions(0), + : patternOptions(0), pattern(), mutex(), compiledPattern(0), studyData(0), errorString(0), errorOffset(-1), @@ -919,7 +920,7 @@ QRegularExpressionPrivate::~QRegularExpressionPrivate() */ QRegularExpressionPrivate::QRegularExpressionPrivate(const QRegularExpressionPrivate &other) : QSharedData(other), - pattern(other.pattern), patternOptions(other.patternOptions), + patternOptions(other.patternOptions), pattern(other.pattern), mutex(), compiledPattern(0), studyData(0), errorString(0), diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 976c03aef4..3619c9e986 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -53,13 +53,17 @@ class QTimeLinePrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QTimeLine) public: inline QTimeLinePrivate() - : startTime(0), duration(1000), startFrame(0), endFrame(0), + : easingCurve(QEasingCurve::InOutSine), + startTime(0), duration(1000), startFrame(0), endFrame(0), updateInterval(1000 / 25), totalLoopCount(1), currentLoopCount(0), currentTime(0), timerId(0), - direction(QTimeLine::Forward), easingCurve(QEasingCurve::InOutSine), + direction(QTimeLine::Forward), state(QTimeLine::NotRunning) { } + QElapsedTimer timer; + QEasingCurve easingCurve; + int startTime; int duration; int startFrame; @@ -70,10 +74,8 @@ public: int currentTime; int timerId; - QElapsedTimer timer; QTimeLine::Direction direction; - QEasingCurve easingCurve; QTimeLine::State state; inline void setState(QTimeLine::State newState) { diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp index 08a5ce0861..ee34469c03 100644 --- a/src/corelib/tools/qtimezoneprivate.cpp +++ b/src/corelib/tools/qtimezoneprivate.cpp @@ -596,9 +596,11 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &zoneId, int offsetSec } QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other) - : QTimeZonePrivate(other), m_offsetFromUtc(other.m_offsetFromUtc), m_name(other.m_name), - m_abbreviation(other.m_abbreviation), m_country(other.m_country), - m_comment(other.m_comment) + : QTimeZonePrivate(other), m_name(other.m_name), + m_abbreviation(other.m_abbreviation), + m_comment(other.m_comment), + m_country(other.m_country), + m_offsetFromUtc(other.m_offsetFromUtc) { } diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h index 108aec2654..4fbb3ff6e0 100644 --- a/src/corelib/tools/qtimezoneprivate_p.h +++ b/src/corelib/tools/qtimezoneprivate_p.h @@ -203,11 +203,11 @@ private: const QString &abbreviation, QLocale::Country country, const QString &comment); - int m_offsetFromUtc; QString m_name; QString m_abbreviation; - QLocale::Country m_country; QString m_comment; + QLocale::Country m_country; + int m_offsetFromUtc; }; #ifdef QT_USE_ICU -- cgit v1.2.3