desktop/qa/desktop_lib/test_desktop_lib.cxx | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
New commits: commit 545e27e7bb31a55ae5ef10fb480864fbf1a79584 Author: Mike Kaganski <[email protected]> AuthorDate: Thu Jun 19 07:27:33 2025 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Thu Jun 19 09:26:22 2025 +0200 Simplify a bit Use string_view to avoid useless allocations. Assert that extension exists first, and avoid checking it second time. Change-Id: I76b27cf975b03da9ce47d0fb5b313a44768910a4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186697 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 7b3f73883078..7a29bcbc818f 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -71,26 +71,20 @@ using namespace com::sun::star; using namespace desktop; -static LibreOfficeKitDocumentType getDocumentTypeFromName(const char* pName) +static LibreOfficeKitDocumentType getDocumentTypeFromName(std::string_view name) { - CPPUNIT_ASSERT_MESSAGE("Document name must be valid.", pName != nullptr); - - const std::string name(pName); CPPUNIT_ASSERT_MESSAGE("Document name must include extension.", name.size() > 4); const auto it = name.rfind('.'); - if (it != std::string::npos) - { - const std::string ext = name.substr(it); + CPPUNIT_ASSERT_MESSAGE("Document name must include extension.", it != std::string::npos); + const std::string_view ext = name.substr(it); - if (ext == ".ods") - return LOK_DOCTYPE_SPREADSHEET; + if (ext == ".ods") + return LOK_DOCTYPE_SPREADSHEET; - if (ext == ".odp") - return LOK_DOCTYPE_PRESENTATION; - } + if (ext == ".odp") + return LOK_DOCTYPE_PRESENTATION; - CPPUNIT_ASSERT_MESSAGE("Document name must include extension.", it != std::string::npos); return LOK_DOCTYPE_TEXT; }
