mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-24 02:40:52 +00:00
Cache method index for GUIInvoke invokes to avoid string compares
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonDocument>
|
||||
#include <QMenu>
|
||||
#include <QMetaMethod>
|
||||
|
||||
bool SaveToJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier, uint32_t magicVersion)
|
||||
{
|
||||
@@ -88,6 +89,14 @@ bool LoadFromJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier,
|
||||
return true;
|
||||
}
|
||||
|
||||
int GUIInvoke::methodIndex = -1;
|
||||
|
||||
void GUIInvoke::init()
|
||||
{
|
||||
GUIInvoke *invoke = new GUIInvoke();
|
||||
methodIndex = invoke->metaObject()->indexOfMethod(QMetaObject::normalizedSignature("doInvoke()"));
|
||||
}
|
||||
|
||||
void GUIInvoke::call(const std::function<void()> &f)
|
||||
{
|
||||
if(qApp->thread() == QThread::currentThread())
|
||||
@@ -96,12 +105,9 @@ void GUIInvoke::call(const std::function<void()> &f)
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: could maybe do away with string compare here via caching
|
||||
// invoke->metaObject()->indexOfMethod("doInvoke"); ?
|
||||
|
||||
GUIInvoke *invoke = new GUIInvoke(f);
|
||||
invoke->moveToThread(qApp->thread());
|
||||
QMetaObject::invokeMethod(invoke, "doInvoke", Qt::QueuedConnection);
|
||||
invoke->metaObject()->method(methodIndex).invoke(invoke, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void GUIInvoke::blockcall(const std::function<void()> &f)
|
||||
@@ -112,12 +118,9 @@ void GUIInvoke::blockcall(const std::function<void()> &f)
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: could maybe do away with string compare here via caching
|
||||
// invoke->metaObject()->indexOfMethod("doInvoke"); ?
|
||||
|
||||
GUIInvoke *invoke = new GUIInvoke(f);
|
||||
invoke->moveToThread(qApp->thread());
|
||||
QMetaObject::invokeMethod(invoke, "doInvoke", Qt::BlockingQueuedConnection);
|
||||
invoke->metaObject()->method(methodIndex).invoke(invoke, Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
void RDDialog::show(QMenu *menu, QPoint pos)
|
||||
|
||||
@@ -55,9 +55,13 @@ class GUIInvoke : public QObject
|
||||
private:
|
||||
Q_OBJECT
|
||||
GUIInvoke(const std::function<void()> &f) : func(f) {}
|
||||
GUIInvoke() {}
|
||||
std::function<void()> func;
|
||||
|
||||
static int methodIndex;
|
||||
|
||||
public:
|
||||
static void init();
|
||||
static void call(const std::function<void()> &f);
|
||||
static void blockcall(const std::function<void()> &f);
|
||||
|
||||
|
||||
@@ -132,6 +132,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
config.SetupFormatting();
|
||||
|
||||
GUIInvoke::init();
|
||||
|
||||
CaptureContext ctx(filename, remoteHost, remoteIdent, temp, config);
|
||||
|
||||
while(ctx.isRunning())
|
||||
|
||||
Reference in New Issue
Block a user