Skip to content

Commit fbe1010

Browse files
paulwickingQt Cherry-pick Bot
authored andcommitted
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 Change-Id: I8a10be7f4eb2754f5c50207b254d977fba2f24ea Reviewed-by: Topi Reiniö <[email protected]> (cherry picked from commit 9da54f2) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
1 parent cd9bffd commit fbe1010

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
@@ -864,12 +864,10 @@ CXChildVisitResult ClangVisitor::visitFnSignature(CXCursor cursor, CXSourceLocat
864864

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

0 commit comments

Comments
 (0)