xcb: replace inefficient uses of QList with QVector
xcb atoms are uint32s, so a QList of them wastes 50% memory on 64-bit platforms. Other parts of the code already store xcb_atom_t's in QVector, so use QVector everywhere (also leads to less code expansion). Change-Id: Ib4afb35e499577a7509d04a18b830d9b31f6abd0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
parent
922815a2a7
commit
e3db3c4d78
@ -135,9 +135,10 @@ protected:
|
||||
|
||||
(void)formats(); // trigger update of format list
|
||||
|
||||
QList<xcb_atom_t> atoms;
|
||||
QVector<xcb_atom_t> atoms;
|
||||
xcb_atom_t *targets = (xcb_atom_t *) format_atoms.data();
|
||||
int size = format_atoms.size() / sizeof(xcb_atom_t);
|
||||
atoms.reserve(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
atoms.append(targets[i]);
|
||||
|
||||
@ -524,7 +525,7 @@ xcb_atom_t QXcbClipboard::sendTargetsSelection(QMimeData *d, xcb_window_t window
|
||||
QVector<xcb_atom_t> types;
|
||||
QStringList formats = QInternalMimeData::formatsHelper(d);
|
||||
for (int i = 0; i < formats.size(); ++i) {
|
||||
QList<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), formats.at(i));
|
||||
QVector<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), formats.at(i));
|
||||
for (int j = 0; j < atoms.size(); ++j) {
|
||||
if (!types.contains(atoms.at(j)))
|
||||
types.append(atoms.at(j));
|
||||
|
@ -183,7 +183,7 @@ void QXcbDrag::startDrag()
|
||||
|
||||
QStringList fmts = QXcbMime::formatsHelper(drag()->mimeData());
|
||||
for (int i = 0; i < fmts.size(); ++i) {
|
||||
QList<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), fmts.at(i));
|
||||
QVector<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), fmts.at(i));
|
||||
for (int j = 0; j < atoms.size(); ++j) {
|
||||
if (!drag_types.contains(atoms.at(j)))
|
||||
drag_types.append(atoms.at(j));
|
||||
@ -1211,7 +1211,7 @@ QVariant QXcbDropData::xdndObtainData(const QByteArray &format, QVariant::Type r
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<xcb_atom_t> atoms = drag->xdnd_types;
|
||||
QVector<xcb_atom_t> atoms = drag->xdnd_types;
|
||||
QByteArray encoding;
|
||||
xcb_atom_t a = mimeAtomForFormat(c, QLatin1String(format), requestedType, atoms, &encoding);
|
||||
if (a == XCB_NONE)
|
||||
|
@ -126,7 +126,7 @@ private:
|
||||
|
||||
// the types in this drop. 100 is no good, but at least it's big.
|
||||
enum { xdnd_max_type = 100 };
|
||||
QList<xcb_atom_t> xdnd_types;
|
||||
QVector<xcb_atom_t> xdnd_types;
|
||||
|
||||
// timestamp from XdndPosition and XdndDroptime for retrieving the data
|
||||
xcb_timestamp_t target_time;
|
||||
|
@ -136,9 +136,10 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<xcb_atom_t> QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, const QString &format)
|
||||
QVector<xcb_atom_t> QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, const QString &format)
|
||||
{
|
||||
QList<xcb_atom_t> atoms;
|
||||
QVector<xcb_atom_t> atoms;
|
||||
atoms.reserve(7);
|
||||
atoms.append(connection->internAtom(format.toLatin1()));
|
||||
|
||||
// special cases for strings
|
||||
@ -240,7 +241,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
}
|
||||
|
||||
xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString &format, QVariant::Type requestedType,
|
||||
const QList<xcb_atom_t> &atoms, QByteArray *requestedEncoding)
|
||||
const QVector<xcb_atom_t> &atoms, QByteArray *requestedEncoding)
|
||||
{
|
||||
requestedEncoding->clear();
|
||||
|
||||
|
@ -59,14 +59,14 @@ public:
|
||||
QXcbMime();
|
||||
~QXcbMime();
|
||||
|
||||
static QList<xcb_atom_t> mimeAtomsForFormat(QXcbConnection *connection, const QString &format);
|
||||
static QVector<xcb_atom_t> mimeAtomsForFormat(QXcbConnection *connection, const QString &format);
|
||||
static QString mimeAtomToString(QXcbConnection *connection, xcb_atom_t a);
|
||||
static bool mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeData *mimeData, QByteArray *data,
|
||||
xcb_atom_t *atomFormat, int *dataFormat);
|
||||
static QVariant mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format,
|
||||
QVariant::Type requestedType, const QByteArray &encoding);
|
||||
static xcb_atom_t mimeAtomForFormat(QXcbConnection *connection, const QString &format, QVariant::Type requestedType,
|
||||
const QList<xcb_atom_t> &atoms, QByteArray *requestedEncoding);
|
||||
const QVector<xcb_atom_t> &atoms, QByteArray *requestedEncoding);
|
||||
};
|
||||
|
||||
#endif // !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
|
||||
|
Loading…
Reference in New Issue
Block a user