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 "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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue