From e54777276d28e6bbceefa07e260926c81790938c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 3 Aug 2020 08:41:49 +0200 Subject: loplugin:flatten in configmgr..i18nutil Change-Id: Idaeed33df4f1dd1b2acbdaf8a895c5d56c3ca14c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99980 Tested-by: Jenkins Reviewed-by: Noel Grandin --- configmgr/source/components.cxx | 132 ++++++++++++++-------------- configmgr/source/rootaccess.cxx | 23 ++--- configmgr/source/writemodfile.cxx | 25 +++--- configmgr/source/xcsparser.cxx | 84 +++++++++--------- cppu/source/typelib/typelib.cxx | 90 +++++++++---------- desktop/source/lib/init.cxx | 128 +++++++++++++-------------- editeng/source/editeng/impedit2.cxx | 20 ++--- i18nutil/source/utility/oneToOneMapping.cxx | 34 +++---- 8 files changed, 270 insertions(+), 266 deletions(-) diff --git a/configmgr/source/components.cxx b/configmgr/source/components.cxx index 7f629bc8afbe..f7bd5ba34e3a 100644 --- a/configmgr/source/components.cxx +++ b/configmgr/source/components.cxx @@ -271,23 +271,24 @@ void Components::addModification(std::vector const & path) { void Components::writeModifications() { - if (!data_.modifications.empty()) { - switch (modificationTarget_) { - case ModificationTarget::None: - break; - case ModificationTarget::File: - if (!writeThread_.is()) { - writeThread_ = new WriteThread( - &writeThread_, *this, modificationFileUrl_, data_); - writeThread_->launch(); - } - break; - case ModificationTarget::Dconf: + if (data_.modifications.empty()) + return; + + switch (modificationTarget_) { + case ModificationTarget::None: + break; + case ModificationTarget::File: + if (!writeThread_.is()) { + writeThread_ = new WriteThread( + &writeThread_, *this, modificationFileUrl_, data_); + writeThread_->launch(); + } + break; + case ModificationTarget::Dconf: #if ENABLE_DCONF - dconf::writeModifications(*this, data_); + dconf::writeModifications(*this, data_); #endif - break; - } + break; } } @@ -349,38 +350,39 @@ void Components::removeExtensionXcuFile( assert(modifications != nullptr); rtl::Reference< Data::ExtensionXcu > item( data_.removeExtensionXcuAdditions(fileUri)); - if (item.is()) { - for (Additions::reverse_iterator i(item->additions.rbegin()); - i != item->additions.rend(); ++i) + if (!item.is()) + return; + + for (Additions::reverse_iterator i(item->additions.rbegin()); + i != item->additions.rend(); ++i) + { + rtl::Reference< Node > parent; + NodeMap const * map = &data_.getComponents(); + rtl::Reference< Node > node; + for (auto const& j : *i) { - rtl::Reference< Node > parent; - NodeMap const * map = &data_.getComponents(); - rtl::Reference< Node > node; - for (auto const& j : *i) - { - parent = node; - node = map->findNode(Data::NO_LAYER, j); - if (!node.is()) { - break; - } - map = &node->getMembers(); + parent = node; + node = map->findNode(Data::NO_LAYER, j); + if (!node.is()) { + break; } - if (node.is()) { - assert(parent.is()); - if (parent->kind() == Node::KIND_SET) { - assert( - node->kind() == Node::KIND_GROUP || - node->kind() == Node::KIND_SET); - if (canRemoveFromLayer(item->layer, node)) { - parent->getMembers().erase(i->back()); - data_.modifications.remove(*i); - modifications->add(*i); - } + map = &node->getMembers(); + } + if (node.is()) { + assert(parent.is()); + if (parent->kind() == Node::KIND_SET) { + assert( + node->kind() == Node::KIND_GROUP || + node->kind() == Node::KIND_SET); + if (canRemoveFromLayer(item->layer, node)) { + parent->getMembers().erase(i->back()); + data_.modifications.remove(*i); + modifications->add(*i); } } } - writeModifications(); } + writeModifications(); } void Components::insertModificationXcuFile( @@ -825,32 +827,32 @@ void Components::parseXcsXcuIniLayer( // Check if ini file exists (otherwise .override would still read global // SCHEMA/DATA variables, which could interfere with unrelated environment // variables): - if (rtl::Bootstrap(url).getHandle() != nullptr) { - OUStringBuffer prefix("${.override:"); - for (sal_Int32 i = 0; i != url.getLength(); ++i) { - sal_Unicode c = url[i]; - switch (c) { - case '$': - case ':': - case '\\': - prefix.append('\\'); - [[fallthrough]]; - default: - prefix.append(c); - } - } - prefix.append(':'); - OUString urls(prefix.toString() + "SCHEMA}"); - rtl::Bootstrap::expandMacros(urls); - if (!urls.isEmpty()) { - parseFileList(layer, &parseXcsFile, urls, false); - } - urls = prefix.makeStringAndClear() + "DATA}"; - rtl::Bootstrap::expandMacros(urls); - if (!urls.isEmpty()) { - parseFileList(layer + 1, &parseXcuFile, urls, recordAdditions); + if (rtl::Bootstrap(url).getHandle() == nullptr) return; + + OUStringBuffer prefix("${.override:"); + for (sal_Int32 i = 0; i != url.getLength(); ++i) { + sal_Unicode c = url[i]; + switch (c) { + case '$': + case ':': + case '\\': + prefix.append('\\'); + [[fallthrough]]; + default: + prefix.append(c); } } + prefix.append(':'); + OUString urls(prefix.toString() + "SCHEMA}"); + rtl::Bootstrap::expandMacros(urls); + if (!urls.isEmpty()) { + parseFileList(layer, &parseXcsFile, urls, false); + } + urls = prefix.makeStringAndClear() + "DATA}"; + rtl::Bootstrap::expandMacros(urls); + if (!urls.isEmpty()) { + parseFileList(layer + 1, &parseXcuFile, urls, recordAdditions); + } } void Components::parseResLayer(int layer, OUString const & url) { diff --git a/configmgr/source/rootaccess.cxx b/configmgr/source/rootaccess.cxx index 17c9f111a27a..a3804fa47d4d 100644 --- a/configmgr/source/rootaccess.cxx +++ b/configmgr/source/rootaccess.cxx @@ -75,17 +75,18 @@ void RootAccess::initBroadcaster( std::vector< css::util::ElementChange > changes; initBroadcasterAndChanges( modifications, broadcaster, changesListeners_.empty() ? nullptr : &changes); - if (!changes.empty()) { - css::util::ChangesSet set(comphelper::containerToSequence(changes)); - for (auto const& changesListener : changesListeners_) - { - cppu::OWeakObject* pSource = this; - css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY ); - broadcaster->addChangesNotification( - changesListener, - css::util::ChangesEvent( - pSource, css::uno::Any( xBase ), set)); - } + if (changes.empty()) + return; + + css::util::ChangesSet set(comphelper::containerToSequence(changes)); + for (auto const& changesListener : changesListeners_) + { + cppu::OWeakObject* pSource = this; + css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY ); + broadcaster->addChangesNotification( + changesListener, + css::util::ChangesEvent( + pSource, css::uno::Any( xBase ), set)); } } diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx index 3df150c448cd..29d4b18c49bf 100644 --- a/configmgr/source/writemodfile.cxx +++ b/configmgr/source/writemodfile.cxx @@ -75,20 +75,21 @@ OString convertToUtf8(std::u16string_view text) { } // anonymous namespace TempFile::~TempFile() { - if (handle != nullptr) { - if (!closed) { - oslFileError e = osl_closeFile(handle); - if (e != osl_File_E_None) { - SAL_WARN("configmgr", "osl_closeFile failed with " << +e); - } - } - osl::FileBase::RC e = osl::File::remove(url); - if (e != osl::FileBase::E_None) { - SAL_WARN( - "configmgr", - "osl::File::remove(" << url << ") failed with " << +e); + if (handle == nullptr) + return; + + if (!closed) { + oslFileError e = osl_closeFile(handle); + if (e != osl_File_E_None) { + SAL_WARN("configmgr", "osl_closeFile failed with " << +e); } } + osl::FileBase::RC e = osl::File::remove(url); + if (e != osl::FileBase::E_None) { + SAL_WARN( + "configmgr", + "osl::File::remove(" << url << ") failed with " << +e); + } } #ifdef _WIN32 diff --git a/configmgr/source/xcsparser.cxx b/configmgr/source/xcsparser.cxx index 7b1750b20972..947792c0a62e 100644 --- a/configmgr/source/xcsparser.cxx +++ b/configmgr/source/xcsparser.cxx @@ -55,54 +55,54 @@ void merge( assert( original.is() && update.is() && original->kind() == update->kind() && update->getFinalized() == Data::NO_LAYER); - if (update->getLayer() >= original->getLayer() && - update->getLayer() <= original->getFinalized()) - { - switch (original->kind()) { - case Node::KIND_PROPERTY: - case Node::KIND_LOCALIZED_PROPERTY: - case Node::KIND_LOCALIZED_VALUE: - break; //TODO: merge certain parts? - case Node::KIND_GROUP: - for (auto const& updateMember : update->getMembers()) - { - NodeMap & members = original->getMembers(); - NodeMap::iterator i1(members.find(updateMember.first)); - if (i1 == members.end()) { - if (updateMember.second->kind() == Node::KIND_PROPERTY && - static_cast< GroupNode * >( - original.get())->isExtensible()) - { - members.insert(updateMember); - } - } else if (updateMember.second->kind() == i1->second->kind()) { - merge(i1->second, updateMember.second); + if (update->getLayer() < original->getLayer() || + update->getLayer() > original->getFinalized()) + return; + + switch (original->kind()) { + case Node::KIND_PROPERTY: + case Node::KIND_LOCALIZED_PROPERTY: + case Node::KIND_LOCALIZED_VALUE: + break; //TODO: merge certain parts? + case Node::KIND_GROUP: + for (auto const& updateMember : update->getMembers()) + { + NodeMap & members = original->getMembers(); + NodeMap::iterator i1(members.find(updateMember.first)); + if (i1 == members.end()) { + if (updateMember.second->kind() == Node::KIND_PROPERTY && + static_cast< GroupNode * >( + original.get())->isExtensible()) + { + members.insert(updateMember); } + } else if (updateMember.second->kind() == i1->second->kind()) { + merge(i1->second, updateMember.second); } - break; - case Node::KIND_SET: - for (auto const& updateMember : update->getMembers()) - { - NodeMap & members = original->getMembers(); - NodeMap::iterator i1(members.find(updateMember.first)); - if (i1 == members.end()) { - if (static_cast< SetNode * >(original.get())-> - isValidTemplate(updateMember.second->getTemplateName())) - { - members.insert(updateMember); - } - } else if (updateMember.second->kind() == i1->second->kind() && - (updateMember.second->getTemplateName() == - i1->second->getTemplateName())) + } + break; + case Node::KIND_SET: + for (auto const& updateMember : update->getMembers()) + { + NodeMap & members = original->getMembers(); + NodeMap::iterator i1(members.find(updateMember.first)); + if (i1 == members.end()) { + if (static_cast< SetNode * >(original.get())-> + isValidTemplate(updateMember.second->getTemplateName())) { - merge(i1->second, updateMember.second); + members.insert(updateMember); } + } else if (updateMember.second->kind() == i1->second->kind() && + (updateMember.second->getTemplateName() == + i1->second->getTemplateName())) + { + merge(i1->second, updateMember.second); } - break; - case Node::KIND_ROOT: - assert(false); // this cannot happen - break; } + break; + case Node::KIND_ROOT: + assert(false); // this cannot happen + break; } } diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index d9f445272510..8b8f7d1b32f1 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -1366,68 +1366,68 @@ extern "C" void SAL_CALL typelib_typedescription_release( { sal_Int32 ref = osl_atomic_decrement( &pTD->nRefCount ); OSL_ASSERT(ref >= 0); - if (0 == ref) + if (0 != ref) + return; + + TypeDescriptor_Init_Impl &rInit = Init::get(); + if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) ) { - TypeDescriptor_Init_Impl &rInit = Init::get(); - if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) ) + if( pTD->pWeakRef ) { - if( pTD->pWeakRef ) { - { MutexGuard aGuard( rInit.getMutex() ); // remove this description from the weak reference pTD->pWeakRef->pType = nullptr; - } - typelib_typedescriptionreference_release( pTD->pWeakRef ); } + typelib_typedescriptionreference_release( pTD->pWeakRef ); } - else + } + else + { + // this description is a reference too, so remove it from the hash table + if( rInit.pWeakMap ) { - // this description is a reference too, so remove it from the hash table - if( rInit.pWeakMap ) + MutexGuard aGuard( rInit.getMutex() ); + WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pTD->pTypeName->buffer ); + if( aIt != rInit.pWeakMap->end() && static_cast((*aIt).second) == static_cast(pTD) ) { - MutexGuard aGuard( rInit.getMutex() ); - WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pTD->pTypeName->buffer ); - if( aIt != rInit.pWeakMap->end() && static_cast((*aIt).second) == static_cast(pTD) ) - { - // remove only if it contains the same object - rInit.pWeakMap->erase( aIt ); - } + // remove only if it contains the same object + rInit.pWeakMap->erase( aIt ); } } + } - typelib_typedescription_destructExtendedMembers( pTD ); - rtl_uString_release( pTD->pTypeName ); + typelib_typedescription_destructExtendedMembers( pTD ); + rtl_uString_release( pTD->pTypeName ); #if OSL_DEBUG_LEVEL > 0 - switch( pTD->eTypeClass ) - { - case typelib_TypeClass_SEQUENCE: - osl_atomic_decrement( &rInit.nIndirectTypeDescriptionCount ); - break; - case typelib_TypeClass_STRUCT: - case typelib_TypeClass_EXCEPTION: - osl_atomic_decrement( &rInit.nCompoundTypeDescriptionCount ); - break; - case typelib_TypeClass_INTERFACE: - osl_atomic_decrement( &rInit.nInterfaceTypeDescriptionCount ); - break; - case typelib_TypeClass_INTERFACE_METHOD: - osl_atomic_decrement( &rInit.nInterfaceMethodTypeDescriptionCount ); - break; - case typelib_TypeClass_INTERFACE_ATTRIBUTE: - osl_atomic_decrement( &rInit.nInterfaceAttributeTypeDescriptionCount ); - break; - case typelib_TypeClass_ENUM: - osl_atomic_decrement( &rInit.nEnumTypeDescriptionCount ); - break; - default: - osl_atomic_decrement( &rInit.nTypeDescriptionCount ); - } + switch( pTD->eTypeClass ) + { + case typelib_TypeClass_SEQUENCE: + osl_atomic_decrement( &rInit.nIndirectTypeDescriptionCount ); + break; + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + osl_atomic_decrement( &rInit.nCompoundTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE: + osl_atomic_decrement( &rInit.nInterfaceTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE_METHOD: + osl_atomic_decrement( &rInit.nInterfaceMethodTypeDescriptionCount ); + break; + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + osl_atomic_decrement( &rInit.nInterfaceAttributeTypeDescriptionCount ); + break; + case typelib_TypeClass_ENUM: + osl_atomic_decrement( &rInit.nEnumTypeDescriptionCount ); + break; + default: + osl_atomic_decrement( &rInit.nTypeDescriptionCount ); + } #endif - freeTypeDescription(pTD); - } + freeTypeDescription(pTD); } diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index bac4d4da4cbd..e844243207d8 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3644,84 +3644,84 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned long if (!pWindow && nWindowId >= 1000000000 /* why unsigned? */) pWindow = getSidebarWindow(); - if (aMap.find("id") != aMap.end()) - { - static const OUString sClickAction("CLICK"); - static const OUString sSelectAction("SELECT"); - static const OUString sClearAction("CLEAR"); - static const OUString sTypeAction("TYPE"); - static const OUString sUpAction("UP"); - static const OUString sDownAction("DOWN"); - static const OUString sValue("VALUE"); + if (aMap.find("id") == aMap.end()) + return; - bool bIsWeldedDialog = false; + static const OUString sClickAction("CLICK"); + static const OUString sSelectAction("SELECT"); + static const OUString sClearAction("CLEAR"); + static const OUString sTypeAction("TYPE"); + static const OUString sUpAction("UP"); + static const OUString sDownAction("DOWN"); + static const OUString sValue("VALUE"); - try - { - OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US); + bool bIsWeldedDialog = false; - bIsWeldedDialog = jsdialog::ExecuteAction(nWindowId, sControlId, aMap); - if (!bIsWeldedDialog) - bIsWeldedDialog = jsdialog::ExecuteAction(reinterpret_cast(SfxViewShell::Current()), - sControlId, aMap); + try + { + OString sControlId = OUStringToOString(aMap["id"], RTL_TEXTENCODING_ASCII_US); - if (!pWindow) - { - SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found."); - return; - } + bIsWeldedDialog = jsdialog::ExecuteAction(nWindowId, sControlId, aMap); + if (!bIsWeldedDialog) + bIsWeldedDialog = jsdialog::ExecuteAction(reinterpret_cast(SfxViewShell::Current()), + sControlId, aMap); - if (!bIsWeldedDialog) - { - WindowUIObject aUIObject(pWindow); - std::unique_ptr pUIWindow(aUIObject.get_child(aMap["id"])); - if (pUIWindow) { - bool bIsClickAction = false; + if (!pWindow) + { + SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found."); + return; + } - if (aMap.find("cmd") != aMap.end()) { - if (aMap["cmd"] == "selected") - { - aMap["POS"] = aMap["data"]; - aMap["TEXT"] = aMap["data"]; + if (!bIsWeldedDialog) + { + WindowUIObject aUIObject(pWindow); + std::unique_ptr pUIWindow(aUIObject.get_child(aMap["id"])); + if (pUIWindow) { + bool bIsClickAction = false; - pUIWindow->execute(sSelectAction, aMap); - } - else if (aMap["cmd"] == "plus") - { - pUIWindow->execute(sUpAction, aMap); - } - else if (aMap["cmd"] == "minus") - { - pUIWindow->execute(sDownAction, aMap); - } - else if (aMap["cmd"] == "set") - { - aMap["TEXT"] = aMap["data"]; + if (aMap.find("cmd") != aMap.end()) { + if (aMap["cmd"] == "selected") + { + aMap["POS"] = aMap["data"]; + aMap["TEXT"] = aMap["data"]; - pUIWindow->execute(sClearAction, aMap); - pUIWindow->execute(sTypeAction, aMap); - } - else if (aMap["cmd"] == "value") - { - aMap["VALUE"] = aMap["data"]; - pUIWindow->execute(sValue, aMap); - } - else - bIsClickAction = true; + pUIWindow->execute(sSelectAction, aMap); + } + else if (aMap["cmd"] == "plus") + { + pUIWindow->execute(sUpAction, aMap); + } + else if (aMap["cmd"] == "minus") + { + pUIWindow->execute(sDownAction, aMap); + } + else if (aMap["cmd"] == "set") + { + aMap["TEXT"] = aMap["data"]; + + pUIWindow->execute(sClearAction, aMap); + pUIWindow->execute(sTypeAction, aMap); + } + else if (aMap["cmd"] == "value") + { + aMap["VALUE"] = aMap["data"]; + pUIWindow->execute(sValue, aMap); } else bIsClickAction = true; - - if (bIsClickAction) - pUIWindow->execute(sClickAction, aMap); } + else + bIsClickAction = true; + + if (bIsClickAction) + pUIWindow->execute(sClickAction, aMap); } - } catch(...) {} + } + } catch(...) {} - // force resend - if (!bIsWeldedDialog) - pWindow->Resize(); - } + // force resend + if (!bIsWeldedDialog) + pWindow->Resize(); } static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished) diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index d562037cc237..a94fcf958722 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -4185,18 +4185,18 @@ void ImpEditEngine::CalcHeight( ParaPortion* pPortion ) // I find it not so good, but Writer3 feature: // Check if distance by LineSpacing > Lower: this value is not // stuck in the height of PrevPortion. - if ( !pPrev->IsInvalid() ) + if ( pPrev->IsInvalid() ) + return; + + nExtraSpace = GetYValue( lcl_CalcExtraSpace( rPrevLSItem ) ); + if ( nExtraSpace > nPrevLower ) { - nExtraSpace = GetYValue( lcl_CalcExtraSpace( rPrevLSItem ) ); - if ( nExtraSpace > nPrevLower ) + sal_uInt16 nMoreLower = nExtraSpace - nPrevLower; + // Paragraph becomes 'bigger', 'grows' downwards: + if ( nMoreLower > pPortion->nFirstLineOffset ) { - sal_uInt16 nMoreLower = nExtraSpace - nPrevLower; - // Paragraph becomes 'bigger', 'grows' downwards: - if ( nMoreLower > pPortion->nFirstLineOffset ) - { - pPortion->nHeight += ( nMoreLower - pPortion->nFirstLineOffset ); - pPortion->nFirstLineOffset = nMoreLower; - } + pPortion->nHeight += ( nMoreLower - pPortion->nFirstLineOffset ); + pPortion->nFirstLineOffset = nMoreLower; } } } diff --git a/i18nutil/source/utility/oneToOneMapping.cxx b/i18nutil/source/utility/oneToOneMapping.cxx index ea8afdeb1fcc..fbb7054d91cc 100644 --- a/i18nutil/source/utility/oneToOneMapping.cxx +++ b/i18nutil/source/utility/oneToOneMapping.cxx @@ -70,27 +70,27 @@ oneToOneMappingWithFlag::~oneToOneMappingWithFlag() void oneToOneMappingWithFlag::makeIndex() { - if( !mbHasIndex && mpTableWF ) - { - int current = -1; + if( mbHasIndex || !mpTableWF ) + return; + + int current = -1; - for( size_t k = 0; k < mnSize; k++ ) + for( size_t k = 0; k < mnSize; k++ ) + { + const int high = (mpTableWF[k].first >> 8) & 0xFF; + const int low = (mpTableWF[k].first) & 0xFF; + if( high != current ) { - const int high = (mpTableWF[k].first >> 8) & 0xFF; - const int low = (mpTableWF[k].first) & 0xFF; - if( high != current ) - { - current = high; - mpIndex[high].reset(new UnicodePairWithFlag const *[256]); - - for (int j = 0; j < 256; ++j) - mpIndex[high][j] = nullptr; - } - mpIndex[high][low] = &mpTableWF[k]; - } + current = high; + mpIndex[high].reset(new UnicodePairWithFlag const *[256]); - mbHasIndex = true; + for (int j = 0; j < 256; ++j) + mpIndex[high][j] = nullptr; + } + mpIndex[high][low] = &mpTableWF[k]; } + + mbHasIndex = true; } sal_Unicode oneToOneMappingWithFlag::find( const sal_Unicode nKey ) const -- cgit