Skip to content

Commit 9da54f2

Browse files
committed
QDoc: Drop string comparison in favor of Clang API call
This amends commit `d31d4735e21d5a8338c305b8e801a07572a93db6`. The implementation in the aforementioned commit employed a string comparison to ascertain whether the declared return type was `auto`. This string comparison is performed twice per case; once for the function declaration that represents the input to the `\fn` command, and once for the return type set on the related `FunctionNode`. This patch replaces said string comparisons by obtaining the necessary information from Clang's API, reducing the number of string allocations and avoiding the two string comparisons entirely. Task-number: QTBUG-126537 Pick-to: 6.8 Change-Id: I8a10be7f4eb2754f5c50207b254d977fba2f24ea Reviewed-by: Topi Reiniö <[email protected]>
1 parent 1a655fd commit 9da54f2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/qdoc/qdoc/src/qdoc/clangcodeparser.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,12 +863,10 @@ CXChildVisitResult ClangVisitor::visitFnSignature(CXCursor cursor, CXSourceLocat
863863

864864
const clang::Decl* declaration = get_cursor_declaration(cursor);
865865
assert(declaration);
866-
const auto function_declaration = declaration->getAsFunction();
867-
if (function_declaration) {
868-
const auto declaredReturnType = QString::fromStdString(function_declaration->getDeclaredReturnType().getAsString());
869-
const QLatin1String autoString{"auto"};
870-
if (fn->returnType() != autoString && declaredReturnType == autoString)
871-
fn->setDeclaredReturnType(declaredReturnType);
866+
if (const auto function_declaration = declaration->getAsFunction()) {
867+
auto declaredReturnType = function_declaration->getDeclaredReturnType();
868+
if (llvm::dyn_cast_if_present<clang::AutoType>(declaredReturnType.getTypePtrOrNull()))
869+
fn->setDeclaredReturnType(QString::fromStdString(declaredReturnType.getAsString()));
872870
}
873871
}
874872
} else { // Possibly an implicitly generated special member

0 commit comments

Comments
 (0)