summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libshiboken/typeresolver.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/libshiboken/typeresolver.cpp b/libshiboken/typeresolver.cpp
index e69f7f8d..d1439ef8 100644
--- a/libshiboken/typeresolver.cpp
+++ b/libshiboken/typeresolver.cpp
@@ -116,22 +116,25 @@ PyTypeObject* TypeResolver::pythonType()
TypeResolver::Type TypeResolver::getType(const char* name)
{
- std::string typeName(name);
- int len = typeName.size() - 1;
- if (len > 1) {
- if (typeName[len] == '*')
- typeName.erase(len, 1);
-
- TypeResolver *resolver = TypeResolver::get(typeName.c_str());
- if (resolver)
- return TypeResolver::ValueType;
-
- typeName += '*';
- resolver = TypeResolver::get(typeName.c_str());
- if (resolver)
- return TypeResolver::ObjectType;
+ int len = strlen(name);
+ bool isObjTypeName = name[len - 1] == '*';
+ if (TypeResolver::get(name)) {
+ // great, we found the type in our first attempt!
+ return isObjTypeName ? ObjectType : ValueType;
+ } else {
+ // Type not found... let's copy the string.
+ std::string typeName;
+ typeName.reserve(len + 2);
+ if (isObjTypeName)
+ typeName.erase(len - 1, 1);
+ else
+ typeName += '*';
+ isObjTypeName = !isObjTypeName;
+
+ if (TypeResolver::get(typeName.c_str()))
+ return isObjTypeName ? ObjectType : ValueType;
+ else
+ return UnknownType;
}
-
- return TypeResolver::UnknownType;
}