From e7ea25bea293bdd17ac34f4c780dfdeae3afb82d Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Thu, 13 Feb 2025 20:26:50 +0100 Subject: [PATCH] Base: Use pass by value instead of reference as size is small --- src/Base/Type.cpp | 15 ++++++--------- src/Base/Type.h | 8 ++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Base/Type.cpp b/src/Base/Type.cpp index 40ae71e4e0..91605898ba 100644 --- a/src/Base/Type.cpp +++ b/src/Base/Type.cpp @@ -129,7 +129,7 @@ std::string Type::getModuleName(const char* ClassName) } -Type Type::createType(const Type& parent, const char* name, instantiationMethod method) +Type Type::createType(const Type parent, const char* name, instantiationMethod method) { Type newType; newType.index = static_cast(Type::typedata.size()); @@ -193,9 +193,8 @@ Type Type::getParent() const return typedata[index]->parent; } -bool Type::isDerivedFrom(const Type& type) const +bool Type::isDerivedFrom(const Type type) const { - Type temp(*this); do { if (temp == type) { @@ -207,7 +206,7 @@ bool Type::isDerivedFrom(const Type& type) const return false; } -int Type::getAllDerivedFrom(const Type& type, std::vector& List) +int Type::getAllDerivedFrom(const Type type, std::vector& List) { int cnt = 0; @@ -225,15 +224,13 @@ int Type::getNumTypes() return static_cast(typedata.size()); } -Type Type::getTypeIfDerivedFrom(const char* name, const Type& parent, bool bLoadModule) +Type Type::getTypeIfDerivedFrom(const char* name, const Type parent, bool loadModule) { - if (bLoadModule) { + if (loadModule) { importModule(name); } - Type type = fromName(name); - - if (type.isDerivedFrom(parent)) { + if (Type type(fromName(name)); type.isDerivedFrom(parent)) { return type; } diff --git a/src/Base/Type.h b/src/Base/Type.h index b54455e566..1bcc25edc4 100644 --- a/src/Base/Type.h +++ b/src/Base/Type.h @@ -101,17 +101,17 @@ public: static Type fromKey(unsigned int key); const char* getName() const; Type getParent() const; - bool isDerivedFrom(const Type& type) const; + bool isDerivedFrom(const Type type) const; - static int getAllDerivedFrom(const Type& type, std::vector& List); + static int getAllDerivedFrom(const Type type, std::vector& List); /// Returns the given named type if is derived from parent type, otherwise return bad type static Type - getTypeIfDerivedFrom(const char* name, const Type& parent, bool bLoadModule = false); + getTypeIfDerivedFrom(const char* name, const Type parent, bool loadModule = false); static int getNumTypes(); static Type - createType(const Type& parent, const char* name, instantiationMethod method = nullptr); + createType(const Type parent, const char* name, instantiationMethod method = nullptr); unsigned int getKey() const; bool isBad() const;