core/generation: short circuit findObjectGeneration if only one exists

This commit is contained in:
outfoxxed 2024-11-17 01:46:49 -08:00
parent 29d31f5d3b
commit 7db3772641
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 7 additions and 5 deletions

View file

@ -24,7 +24,7 @@
#include "reload.hpp"
#include "scan.hpp"
static QHash<QQmlEngine*, EngineGeneration*> g_generations; // NOLINT
static QHash<const QQmlEngine*, EngineGeneration*> g_generations; // NOLINT
EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
: rootPath(rootPath)
@ -326,11 +326,13 @@ EngineGeneration* EngineGeneration::currentGeneration() {
} else return nullptr;
}
EngineGeneration* EngineGeneration::findEngineGeneration(QQmlEngine* engine) {
EngineGeneration* EngineGeneration::findEngineGeneration(const QQmlEngine* engine) {
return g_generations.value(engine);
}
EngineGeneration* EngineGeneration::findObjectGeneration(QObject* object) {
EngineGeneration* EngineGeneration::findObjectGeneration(const QObject* object) {
if (g_generations.size() == 1) return EngineGeneration::currentGeneration();
while (object != nullptr) {
auto* context = QQmlEngine::contextForObject(object);

View file

@ -45,8 +45,8 @@ public:
void registerExtension(const void* key, EngineGenerationExt* extension);
EngineGenerationExt* findExtension(const void* key);
static EngineGeneration* findEngineGeneration(QQmlEngine* engine);
static EngineGeneration* findObjectGeneration(QObject* object);
static EngineGeneration* findEngineGeneration(const QQmlEngine* engine);
static EngineGeneration* findObjectGeneration(const QObject* object);
// Returns the current generation if there is only one generation,
// otherwise null.