[icinga-checkins] icinga.org: icinga2/feature/gelf-writer-7619: Avoid unnecessary type lookups

git at icinga.org git at icinga.org
Tue Nov 11 14:16:58 CET 2014


Module: icinga2
Branch: feature/gelf-writer-7619
Commit: 65be09215ff9cbc9390f284c6a6331920db08d55
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=65be09215ff9cbc9390f284c6a6331920db08d55

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Nov 10 20:06:28 2014 +0100

Avoid unnecessary type lookups

refs #7622

---

 lib/base/type.hpp               |    6 +++---
 lib/cli/clicommand.cpp          |    4 ++--
 lib/config/expression.cpp       |    2 +-
 tools/mkclass/classcompiler.cpp |    4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/base/type.hpp b/lib/base/type.hpp
index 610a493..2ae1854 100644
--- a/lib/base/type.hpp
+++ b/lib/base/type.hpp
@@ -41,12 +41,12 @@ class Type;
 struct Field
 {
 	int ID;
-	intrusive_ptr<Type> FType;
+	const char *TypeName;
 	const char *Name;
 	int Attributes;
 
-	Field(int id, const intrusive_ptr<Type>& type, const char *name, int attributes)
-		: ID(id), FType(type), Name(name), Attributes(attributes)
+	Field(int id, const char *type, const char *name, int attributes)
+		: ID(id), TypeName(type), Name(name), Attributes(attributes)
 	{ }
 };
 
diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp
index 429e573..79bcf14 100644
--- a/lib/cli/clicommand.cpp
+++ b/lib/cli/clicommand.cpp
@@ -78,8 +78,8 @@ std::vector<String> icinga::GetFieldCompletionSuggestions(const Type::Ptr& type,
 		if (!(field.Attributes & FAConfig) || field.Attributes & FAInternal)
 			continue;
 
-		if (field.FType != Type::GetByName("int") && field.FType != Type::GetByName("double")
-		    && field.FType != Type::GetByName("bool") && field.FType != Type::GetByName("String"))
+		if (strcmp(field.TypeName, "int") != 0 && strcmp(field.TypeName, "double") != 0
+		    && strcmp(field.TypeName, "bool") != 0 && strcmp(field.TypeName, "String") != 0)
 			continue;
 
 		String fname = field.Name;
diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp
index db86ddf..7135e4c 100644
--- a/lib/config/expression.cpp
+++ b/lib/config/expression.cpp
@@ -373,7 +373,7 @@ Value IndexerExpression::DoEvaluate(const Object::Ptr& context, DebugHint *dhint
 	} else if (value.IsObjectType<Array>()) {
 		Array::Ptr arr = value;
 		return arr->Get(index);
-	} else if (value.IsObjectType<Object>()) {
+	} else if (value.IsObject()) {
 		Object::Ptr object = value;
 		Type::Ptr type = object->GetReflectionType();
 
diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp
index f2fe691..e86c552 100644
--- a/tools/mkclass/classcompiler.cpp
+++ b/tools/mkclass/classcompiler.cpp
@@ -299,14 +299,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
 		for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
 			std::string ftype = it->Type;
 
-			if (ftype.find("::Ptr") == ftype.size() - strlen("::Ptr"))
+			if (ftype.find("::Ptr") != std::string::npos)
 				ftype = ftype.substr(0, ftype.size() - strlen("::Ptr"));
 
 			if (it->Attributes & FAEnum)
 				ftype = "int";
 
 			std::cout << "\t\t\t" << "case " << num << ":" << std::endl
-				<< "\t\t\t\t" << "return Field(" << num << ", Type::GetByName(\"" << ftype << "\"), \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
+				<< "\t\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
 			num++;
 		}
 



More information about the icinga-checkins mailing list