From 0aaa1ecd864fc7cb2c1b8f2765687b1fe53d3103 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Jul 2018 10:06:48 +0200 Subject: shiboken: Cache TypeInfo in clangbuilder Add a cache containing the TypeInfo for the CXType structs. Task-number: PYSIDE-672 Change-Id: Ibd0b5bb3f01fa507a65ded8f121c12a10aa7c401 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Alexandru Croitor --- .../ApiExtractor/clangparser/clangbuilder.cpp | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp') diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index 9d0d69c27..633e5bac0 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -146,6 +146,7 @@ class BuilderPrivate { public: typedef QHash CursorClassHash; typedef QHash CursorTypedefHash; + typedef QHash TypeInfoHash; explicit BuilderPrivate(BaseVisitor *bv) : m_baseVisitor(bv), m_model(new CodeModel) { @@ -180,6 +181,7 @@ public: CodeModel::FunctionType t = CodeModel::Normal) const; FunctionModelItem createMemberFunction(const CXCursor &cursor) const; void qualifyConstructor(const CXCursor &cursor); + TypeInfo createTypeInfoHelper(const CXType &type) const; // uncashed TypeInfo createTypeInfo(const CXType &type) const; TypeInfo createTypeInfo(const CXCursor &cursor) const { return createTypeInfo(clang_getCursorType(cursor)); } @@ -209,6 +211,8 @@ public: CursorClassHash m_cursorClassHash; CursorTypedefHash m_cursorTypedefHash; + mutable TypeInfoHash m_typeInfoHash; // Cache type information + ClassModelItem m_currentClass; EnumModelItem m_currentEnum; FunctionModelItem m_currentFunction; @@ -260,7 +264,7 @@ FunctionModelItem BuilderPrivate::createFunction(const CXCursor &cursor, name = fixTypeName(name); FunctionModelItem result(new _FunctionModelItem(m_model, name)); setFileName(cursor, result.data()); - result->setType(createTypeInfo(clang_getCursorResultType(cursor))); + result->setType(createTypeInfoHelper(clang_getCursorResultType(cursor))); result->setFunctionType(t); result->setScope(m_scope); result->setStatic(clang_Cursor_getStorageClass(cursor) == CX_SC_Static); @@ -339,7 +343,7 @@ TemplateParameterModelItem BuilderPrivate::createTemplateParameter(const CXCurso TemplateParameterModelItem BuilderPrivate::createNonTypeTemplateParameter(const CXCursor &cursor) const { TemplateParameterModelItem result = createTemplateParameter(cursor); - result->setType(createTypeInfo(cursor)); + result->setType(createTypeInfoHelper(clang_getCursorType(cursor))); return result; } @@ -409,7 +413,7 @@ bool BuilderPrivate::addTemplateInstantiationsRecursion(const CXType &type, Type // of a non-type template (template ). if (argType.kind == CXType_Invalid) return false; - t->addInstantiation(createTypeInfo(argType)); + t->addInstantiation(createTypeInfoHelper(argType)); } } break; @@ -443,16 +447,16 @@ void BuilderPrivate::addTemplateInstantiations(const CXType &type, typeName->remove(pos.first, pos.second - pos.first); } -TypeInfo BuilderPrivate::createTypeInfo(const CXType &type) const +TypeInfo BuilderPrivate::createTypeInfoHelper(const CXType &type) const { if (type.kind == CXType_Pointer) { // Check for function pointers, first. const CXType pointeeType = clang_getPointeeType(type); const int argCount = clang_getNumArgTypes(pointeeType); if (argCount >= 0) { - TypeInfo result = createTypeInfo(clang_getResultType(pointeeType)); + TypeInfo result = createTypeInfoHelper(clang_getResultType(pointeeType)); result.setFunctionPointer(true); for (int a = 0; a < argCount; ++a) - result.addArgument(createTypeInfo(clang_getArgType(pointeeType, unsigned(a)))); + result.addArgument(createTypeInfoHelper(clang_getArgType(pointeeType, unsigned(a)))); return result; } } @@ -502,6 +506,14 @@ TypeInfo BuilderPrivate::createTypeInfo(const CXType &type) const return typeInfo; } +TypeInfo BuilderPrivate::createTypeInfo(const CXType &type) const +{ + TypeInfoHash::iterator it = m_typeInfoHash.find(type); + if (it == m_typeInfoHash.end()) + it = m_typeInfoHash.insert(type, createTypeInfoHelper(type)); + return it.value(); +} + // extract an expression from the cursor via source // CXCursor_EnumConstantDecl, ParmDecl (a = Flag1 | Flag2) QString BuilderPrivate::cursorValueExpression(BaseVisitor *bv, const CXCursor &cursor) const -- cgit v1.2.3