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 <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2013-09-29 18:07:23 -07:00 committed by The Qt Project
parent 28d77c24c2
commit 9fc0965d19
11 changed files with 72 additions and 63 deletions

View File

@ -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 &copy)
: QSharedData(copy)
, fileListsInitialized(false)
, nameFilters(copy.nameFilters)
, sort(copy.sort)
, filters(copy.filters)
, fileListsInitialized(false)
, dirEntry(copy.dirEntry)
, metaData(copy.metaData)
{

View File

@ -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<QAbstractFileEngine> fileEngine;
mutable bool fileListsInitialized;
mutable QStringList files;
mutable QFileInfoList fileInfos;
QFileSystemEntry dirEntry;
mutable QFileSystemEntry absoluteDirEntry;
mutable QFileSystemMetaData metaData;

View File

@ -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)
{
}

View File

@ -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

View File

@ -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

View File

@ -432,14 +432,14 @@ struct BezierEase : public QEasingCurveFunction
qreal p3x, p3y;
};
QVector<SingleCubicBezier> _curves;
QVector<qreal> _intervals;
int _curveCount;
bool _init;
bool _valid;
QVector<SingleCubicBezier> _curves;
int _curveCount;
QVector<qreal> _intervals;
BezierEase()
: QEasingCurveFunction(InOut), _init(false), _valid(false), _curves(10), _intervals(10)
: QEasingCurveFunction(InOut), _curves(10), _intervals(10), _init(false), _valid(false)
{ }
void init()

View File

@ -1045,12 +1045,12 @@ public:
#endif
private:
uint c; // character classes
QVector<QRegExpCharClassRange> r; // character ranges
bool n; // negative?
#ifndef QT_NO_REGEXP_OPTIM
QVector<int> occ1; // first-occurrence array
#endif
uint c; // character classes
bool n; // negative?
};
#else
struct QRegExpCharClass

View File

@ -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),

View File

@ -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)
{

View File

@ -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)
{
}

View File

@ -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