diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-25 23:00:25 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-26 13:56:11 +0200 |
commit | 1a8923df9c9fbc5c55826fa43ab817ff3f28be0d (patch) | |
tree | 455058cad049ac2a1fb33d99c3a3c47f06cc978f /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | 29bd6b68ea241ae3a7c29103d8a79d80b79f233c (diff) |
shiboken6: Refactor multiple inheritance offset calculation
- Avoid std::set allocation by using standard algorithms operating
on the int array instead.
- Fix one-time initialization for hierarchies where all offsets
are 0 by using -2 as magic constant.
- Reduce mutex lock operations by initializing all base addresses in
the wrapper map in one go.
- Reduce mutex lock operations by releasing the base addresses in the
wrapper map in one go.
Pick-to: 6.6
Task-number: PYSIDE-2506
Change-Id: I7c19b4287a9fcb7a47894b0a06bbeb5698cff7d7
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index a68dc62e4..e56982b6c 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -3991,20 +3991,24 @@ void CppGenerator::writeMultipleInheritanceInitializerFunction(TextStream &s, s << "int *\n" << multipleInheritanceInitializerFunctionName(metaClass) << "(const void *cptr)\n" << "{\n" << indent; - s << "static int mi_offsets[] = { "; + s << "static int mi_offsets[] = {-2"; for (qsizetype i = 0; i < ancestors.size(); i++) - s << "-1, "; - s << "-1 };\n" - << "if (mi_offsets[0] == -1) {\n" << indent - << "std::set<int> offsets;\n" - << "const auto *class_ptr = reinterpret_cast<const " << className << " *>(cptr);\n" - << "const auto base = reinterpret_cast<uintptr_t>(class_ptr);\n"; + s << ", 0"; + s << "};\n" + << "if (mi_offsets[0] == -2) {\n" << indent + << "const auto *class_ptr = reinterpret_cast<const " << className << " *>(cptr);\n" + << "const auto base = reinterpret_cast<uintptr_t>(class_ptr);\n" + << "int *p = mi_offsets;\n"; for (const QString &ancestor : ancestors) - s << "offsets.insert(int(" << ancestor << "));\n"; - - s << "\noffsets.erase(0);\n\n" - << "std::copy(offsets.cbegin(), offsets.cend(), mi_offsets);\n" << outdent + s << "*p++ = int(" << ancestor << ");\n"; + s << "std::sort(mi_offsets, p);\n" + << "auto *end = std::unique(mi_offsets, p);\n" + << "*end++ = -1;\n" + << "if (mi_offsets[0] == 0)\n" + << indent + << "std::memmove(&mi_offsets[0], &mi_offsets[1], (end - mi_offsets - 1) * sizeof(int));\n" + << outdent << outdent << "}\nreturn mi_offsets;\n" << outdent << "}\n"; } |