summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>2012-10-02 09:40:42 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-12 02:19:36 +0200
commit79cbdb503aec471cfb1dfcc7b36867490e4ca7ee (patch)
tree4d617817e7fa4ce51d5a66ea561495b3ef53cec1 /src
parent0ef41ffa6f721d07f5dbb5f95004f118295d44f0 (diff)
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')
-rw-r--r--src/corelib/kernel/qobject.cpp8
-rw-r--r--src/corelib/kernel/qobject_p.h21
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp4
-rw-r--r--src/declarative/qml/qdeclarativenotifier_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp4
5 files changed, 27 insertions, 14 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 8961e34e02..9008fb8fb5 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 6521a4fa50..7c56f639a4 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,
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index d8aeef6fb9..9bccb42bd2 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -137,7 +137,9 @@ QDeclarativeBoundSignal::~QDeclarativeBoundSignal()
void QDeclarativeBoundSignal::disconnect()
{
QObjectPrivate * const priv = QObjectPrivate::get(m_scope);
- priv->disconnectNotify(QObjectPrivate::signalSignature(m_signal));
+ QVarLengthArray<char> signalSignature;
+ QObjectPrivate::signalSignature(m_signal, &signalSignature);
+ priv->disconnectNotify(signalSignature.constData());
}
int QDeclarativeBoundSignal::index() const
diff --git a/src/declarative/qml/qdeclarativenotifier_p.h b/src/declarative/qml/qdeclarativenotifier_p.h
index 0e38ec106a..f15efb6883 100644
--- a/src/declarative/qml/qdeclarativenotifier_p.h
+++ b/src/declarative/qml/qdeclarativenotifier_p.h
@@ -217,7 +217,9 @@ void QDeclarativeNotifierEndpoint::disconnect()
QMetaObject::disconnectOne(s->source, s->sourceSignal, target, targetMethod);
QObjectPrivate * const priv = QObjectPrivate::get(s->source);
const QMetaMethod signal = s->source->metaObject()->method(s->sourceSignal);
- priv->disconnectNotify(QObjectPrivate::signalSignature(signal));
+ QVarLengthArray<char> signalSignature;
+ QObjectPrivate::signalSignature(signal, &signalSignature);
+ priv->disconnectNotify(signalSignature.constData());
s->source = 0;
}
} else if (type == NotifierType) {
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index e6b9775fbb..ce4122a62b 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -1634,7 +1634,9 @@ bool QDeclarativePropertyPrivate::connect(QObject *sender, int signal_index,
const QMetaMethod signal = sender->metaObject()->method(signal_index);
QObjectPrivate * const senderPriv = QObjectPrivate::get(sender);
- senderPriv->connectNotify(QObjectPrivate::signalSignature(signal));
+ QVarLengthArray<char> signalSignature;
+ QObjectPrivate::signalSignature(signal, &signalSignature);
+ senderPriv->connectNotify(signalSignature.constData());
return QMetaObject::connect(sender, signal_index, receiver, method_index, type, types);
}