summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-10-02 07:40:42 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-12 00:19:36 (GMT)
commit79cbdb503aec471cfb1dfcc7b36867490e4ca7ee (patch)
tree4d617817e7fa4ce51d5a66ea561495b3ef53cec1 /src/corelib
parent0ef41ffa6f721d07f5dbb5f95004f118295d44f0 (diff)
downloadQt-79cbdb503aec471cfb1dfcc7b36867490e4ca7ee.zip
Qt-79cbdb503aec471cfb1dfcc7b36867490e4ca7ee.tar.gz
Qt-79cbdb503aec471cfb1dfcc7b36867490e4ca7ee.tar.bz2
Use QVarLengthArray when creating the connectNotify() argument
This gets rid of the heap allocation of the QByteArray. This change is not needed in Qt5, as there, QMetaMethod is used as the argument, and therefore there is no need to construct a SIGNAL-compatible string in memory. Change-Id: Ie2023aeb99bc8f792d437ec604e9989a5efe456b Reviewed-by: Alan Alpert <416365416c@gmail.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qobject.cpp8
-rw-r--r--src/corelib/kernel/qobject_p.h21
2 files changed, 18 insertions, 11 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 8961e34..9008fb8 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -54,7 +54,6 @@
#include <qdebug.h>
#include <qhash.h>
#include <qpair.h>
-#include <qvarlengtharray.h>
#include <qset.h>
#include <qsemaphore.h>
#include <qsharedpointer.h>
@@ -2692,7 +2691,8 @@ bool QObject::connect(const QObject *sender, const QMetaMethod &signal,
return false;
}
- QByteArray signalSignature = QObjectPrivate::signalSignature(signal);
+ QVarLengthArray<char> signalSignature;
+ QObjectPrivate::signalSignature(signal, &signalSignature);
{
QByteArray methodSignature;
@@ -2981,9 +2981,9 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
}
}
- QByteArray signalSignature;
+ QVarLengthArray<char> signalSignature;
if (signal.mobj)
- signalSignature = QObjectPrivate::signalSignature(signal);
+ QObjectPrivate::signalSignature(signal, &signalSignature);
{
QByteArray methodSignature;
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 6521a4f..7c56f63 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -62,6 +62,7 @@
#include "QtCore/qreadwritelock.h"
#include "QtCore/qvariant.h"
#include "QtCore/qmetaobject.h"
+#include "QtCore/qvarlengtharray.h"
QT_BEGIN_NAMESPACE
@@ -185,7 +186,8 @@ public:
inline void connectNotify(const char *signal);
inline void disconnectNotify(const char *signal);
- static inline QByteArray signalSignature(const QMetaMethod &signal);
+ static inline void signalSignature(const QMetaMethod &signal,
+ QVarLengthArray<char> *result);
public:
QString objectName;
@@ -247,13 +249,18 @@ inline void QObjectPrivate::disconnectNotify(const char *signal)
q_ptr->disconnectNotify(signal);
}
-inline QByteArray QObjectPrivate::signalSignature(const QMetaMethod &signal)
+inline void QObjectPrivate::signalSignature(const QMetaMethod &signal,
+ QVarLengthArray<char> *result)
{
- QByteArray result;
- result.reserve(qstrlen(signal.signature())+1);
- result.append((char)(QSIGNAL_CODE + '0'));
- result.append(signal.signature());
- return result;
+ Q_ASSERT(result);
+ const int signatureLength = qstrlen(signal.signature());
+ if (signatureLength == 0) {
+ result->append((char)0);
+ return;
+ }
+ result->reserve(signatureLength + 2);
+ result->append((char)(QSIGNAL_CODE + '0'));
+ result->append(signal.signature(), signatureLength + 1);
}
inline QObjectPrivate::Sender *QObjectPrivate::setCurrentSender(QObject *receiver,