]> granicus.if.org Git - icinga2/commitdiff
Avoid unnecessary type lookups
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 10 Nov 2014 19:06:28 +0000 (20:06 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 10 Nov 2014 19:07:07 +0000 (20:07 +0100)
refs #7622

lib/base/type.hpp
lib/cli/clicommand.cpp
lib/config/expression.cpp
tools/mkclass/classcompiler.cpp

index 610a4939fbd049098bdf9d99c5ce9de79191afe3..2ae18547892b6914bcfbdf38b1a42207bd44aa9c 100644 (file)
@@ -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)
        { }
 };
 
index 429e57342b1119a2dbb08d08e463bf6fa988cec5..79bcf14da792d89a6403060810c70628431cf598 100644 (file)
@@ -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;
index db86ddf79fd14d95b3817bbb92e057ffce46b0c9..7135e4c640b314eb45e4274744b428c32d68641a 100644 (file)
@@ -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();
 
index f2fe69102f3093bcc06c94aa24becefee281d31b..e86c55269e2fbf94b75bbcbb18d7b4323a7a54e8 100644 (file)
@@ -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++;
                }