1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

perf: Pass std::function by reference

This commit is contained in:
Diadlo 2017-06-11 21:48:44 +03:00
parent 7895bcdaa0
commit 365d703e8a
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
11 changed files with 15 additions and 15 deletions

View File

@ -25,18 +25,18 @@ public:
{
public:
Query(QString query, QVector<QByteArray> blobs = {},
std::function<void(int64_t)> insertCallback = {})
const std::function<void(int64_t)>& insertCallback = {})
: query{query.toUtf8()}
, blobs{blobs}
, insertCallback{insertCallback}
{
}
Query(QString query, std::function<void(int64_t)> insertCallback)
Query(QString query, const std::function<void(int64_t)>& insertCallback)
: query{query.toUtf8()}
, insertCallback{insertCallback}
{
}
Query(QString query, std::function<void(const QVector<QVariant>&)> rowCallback)
Query(QString query, const std::function<void(const QVector<QVariant>&)>& rowCallback)
: query{query.toUtf8()}
, rowCallback{rowCallback}
{

View File

@ -228,7 +228,7 @@ History::generateNewMessageQueries(const QString& friendPk, const QString& messa
*/
void History::addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
const QDateTime& time, bool isSent, QString dispName,
std::function<void(int64_t)> insertIdCallback)
const std::function<void(int64_t)>& insertIdCallback)
{
if (!isValid()) {
return;

View File

@ -69,7 +69,7 @@ public:
void removeFriendHistory(const QString& friendPk);
void addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
const QDateTime& time, bool isSent, QString dispName,
std::function<void(int64_t)> insertIdCallback = {});
const std::function<void(int64_t)>& insertIdCallback = {});
QList<HistMessage> getChatHistory(const QString& friendPk, const QDateTime& from,
const QDateTime& to);

View File

@ -151,7 +151,7 @@ void CameraSource::open(const QString& deviceName)
open(deviceName, mode);
}
void CameraSource::open(const QString& DeviceName, VideoMode Mode)
void CameraSource::open(const QString& DeviceName, const VideoMode& Mode)
{
QWriteLocker locker{&streamMutex};

View File

@ -41,7 +41,7 @@ public:
static void destroyInstance();
void open();
void open(const QString& deviceName);
void open(const QString& deviceName, VideoMode mode);
void open(const QString& deviceName, const VideoMode& mode);
void close();
bool isOpen();

View File

@ -718,7 +718,7 @@ void VideoFrame::deleteFrameBuffer()
*/
template <typename T>
T VideoFrame::toGenericObject(const QSize& dimensions, const int pixelFormat, const bool requireAligned,
const std::function<T(AVFrame* const)> objectConstructor,
const std::function<T(AVFrame* const)>& objectConstructor,
const T& nullObject)
{
frameLock.lockForRead();
@ -762,10 +762,10 @@ T VideoFrame::toGenericObject(const QSize& dimensions, const int pixelFormat, co
// Explicitly specialize VideoFrame::toGenericObject() function
template QImage VideoFrame::toGenericObject<QImage>(
const QSize& dimensions, const int pixelFormat, const bool requireAligned,
const std::function<QImage(AVFrame* const)> objectConstructor, const QImage& nullObject);
const std::function<QImage(AVFrame* const)> &objectConstructor, const QImage& nullObject);
template ToxYUVFrame VideoFrame::toGenericObject<ToxYUVFrame>(
const QSize& dimensions, const int pixelFormat, const bool requireAligned,
const std::function<ToxYUVFrame(AVFrame* const)> objectConstructor, const ToxYUVFrame& nullObject);
const std::function<ToxYUVFrame(AVFrame* const)> &objectConstructor, const ToxYUVFrame& nullObject);
/**
* @brief Returns whether the given ToxYUVFrame represents a valid frame or not.

View File

@ -133,7 +133,7 @@ private:
template <typename T>
T toGenericObject(const QSize& dimensions, const int pixelFormat, const bool requireAligned,
const std::function<T(AVFrame* const)> objectConstructor, const T& nullObject);
const std::function<T(AVFrame* const)>& objectConstructor, const T& nullObject);
private:
// ID

View File

@ -139,7 +139,7 @@ void VideoSurface::unsubscribe()
disconnect(source, &VideoSource::sourceStopped, this, &VideoSurface::onSourceStopped);
}
void VideoSurface::onNewFrameAvailable(std::shared_ptr<VideoFrame> newFrame)
void VideoSurface::onNewFrameAvailable(const std::shared_ptr<VideoFrame>& newFrame)
{
QSize newSize;

View File

@ -54,7 +54,7 @@ protected:
virtual void showEvent(QShowEvent* event) final override;
private slots:
void onNewFrameAvailable(std::shared_ptr<VideoFrame> newFrame);
void onNewFrameAvailable(const std::shared_ptr<VideoFrame>& newFrame);
void onSourceStopped();
private:

View File

@ -84,7 +84,7 @@ void Translator::translate(const QString& localeName)
* @param f Function, wich will called.
* @param owner Widget to retanslate.
*/
void Translator::registerHandler(std::function<void()> f, void* owner)
void Translator::registerHandler(const std::function<void()>& f, void* owner)
{
QMutexLocker locker{&lock};
callbacks.push_back({owner, f});

View File

@ -32,7 +32,7 @@ class Translator
{
public:
static void translate(const QString& localeName);
static void registerHandler(std::function<void()>, void* owner);
static void registerHandler(const std::function<void()>&, void* owner);
static void unregister(void* owner);
private: