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: public:
Query(QString query, QVector<QByteArray> blobs = {}, Query(QString query, QVector<QByteArray> blobs = {},
std::function<void(int64_t)> insertCallback = {}) const std::function<void(int64_t)>& insertCallback = {})
: query{query.toUtf8()} : query{query.toUtf8()}
, blobs{blobs} , blobs{blobs}
, insertCallback{insertCallback} , insertCallback{insertCallback}
{ {
} }
Query(QString query, std::function<void(int64_t)> insertCallback) Query(QString query, const std::function<void(int64_t)>& insertCallback)
: query{query.toUtf8()} : query{query.toUtf8()}
, insertCallback{insertCallback} , 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()} : query{query.toUtf8()}
, rowCallback{rowCallback} , 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, void History::addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
const QDateTime& time, bool isSent, QString dispName, const QDateTime& time, bool isSent, QString dispName,
std::function<void(int64_t)> insertIdCallback) const std::function<void(int64_t)>& insertIdCallback)
{ {
if (!isValid()) { if (!isValid()) {
return; return;

View File

@ -69,7 +69,7 @@ public:
void removeFriendHistory(const QString& friendPk); void removeFriendHistory(const QString& friendPk);
void addNewMessage(const QString& friendPk, const QString& message, const QString& sender, void addNewMessage(const QString& friendPk, const QString& message, const QString& sender,
const QDateTime& time, bool isSent, QString dispName, 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, QList<HistMessage> getChatHistory(const QString& friendPk, const QDateTime& from,
const QDateTime& to); const QDateTime& to);

View File

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

View File

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

View File

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

View File

@ -133,7 +133,7 @@ private:
template <typename T> template <typename T>
T toGenericObject(const QSize& dimensions, const int pixelFormat, const bool requireAligned, 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: private:
// ID // ID

View File

@ -139,7 +139,7 @@ void VideoSurface::unsubscribe()
disconnect(source, &VideoSource::sourceStopped, this, &VideoSurface::onSourceStopped); 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; QSize newSize;

View File

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

View File

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

View File

@ -32,7 +32,7 @@ class Translator
{ {
public: public:
static void translate(const QString& localeName); 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); static void unregister(void* owner);
private: private: