forked from quickshell/quickshell
		
	core/generation: short circuit findObjectGeneration if only one exists
This commit is contained in:
		
							parent
							
								
									29d31f5d3b
								
							
						
					
					
						commit
						7db3772641
					
				
					 2 changed files with 7 additions and 5 deletions
				
			
		| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
#include "reload.hpp"
 | 
					#include "reload.hpp"
 | 
				
			||||||
#include "scan.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)
 | 
					EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
 | 
				
			||||||
    : rootPath(rootPath)
 | 
					    : rootPath(rootPath)
 | 
				
			||||||
| 
						 | 
					@ -326,11 +326,13 @@ EngineGeneration* EngineGeneration::currentGeneration() {
 | 
				
			||||||
	} else return nullptr;
 | 
						} else return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EngineGeneration* EngineGeneration::findEngineGeneration(QQmlEngine* engine) {
 | 
					EngineGeneration* EngineGeneration::findEngineGeneration(const QQmlEngine* engine) {
 | 
				
			||||||
	return g_generations.value(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) {
 | 
						while (object != nullptr) {
 | 
				
			||||||
		auto* context = QQmlEngine::contextForObject(object);
 | 
							auto* context = QQmlEngine::contextForObject(object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,8 +45,8 @@ public:
 | 
				
			||||||
	void registerExtension(const void* key, EngineGenerationExt* extension);
 | 
						void registerExtension(const void* key, EngineGenerationExt* extension);
 | 
				
			||||||
	EngineGenerationExt* findExtension(const void* key);
 | 
						EngineGenerationExt* findExtension(const void* key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static EngineGeneration* findEngineGeneration(QQmlEngine* engine);
 | 
						static EngineGeneration* findEngineGeneration(const QQmlEngine* engine);
 | 
				
			||||||
	static EngineGeneration* findObjectGeneration(QObject* object);
 | 
						static EngineGeneration* findObjectGeneration(const QObject* object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Returns the current generation if there is only one generation,
 | 
						// Returns the current generation if there is only one generation,
 | 
				
			||||||
	// otherwise null.
 | 
						// otherwise null.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue