diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-27 20:15:17 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-07-29 18:45:04 +0200 |
commit | d458adeed0c34fae26fe7f3d6ecc9b75b431922f (patch) | |
tree | b594540ade488d97d14f93081161a3e77134db63 /sd/source/ui/framework | |
parent | c26f2fcf82d549a6475e9e55cdffde901190635b (diff) |
Simplify Sequence iterations in sd
Use range-based loops, STL and comphelper functions
Change-Id: If4b6d464fc393049dc8d7e5c3faf1cf66b6a369a
Reviewed-on: https://gerrit.libreoffice.org/76480
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'sd/source/ui/framework')
6 files changed, 34 insertions, 65 deletions
diff --git a/sd/source/ui/framework/configuration/Configuration.cxx b/sd/source/ui/framework/configuration/Configuration.cxx index d303b2464156..3fc947c5c92a 100644 --- a/sd/source/ui/framework/configuration/Configuration.cxx +++ b/sd/source/ui/framework/configuration/Configuration.cxx @@ -290,29 +290,14 @@ bool AreConfigurationsEquivalent ( // When the number of resources differ then the configurations can not // be equivalent. - const sal_Int32 nCount (aResources1.getLength()); - const sal_Int32 nCount2 (aResources2.getLength()); - if (nCount != nCount2) - return false; - // Comparison of the two lists of resource ids relies on their // ordering. - for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex) - { - const Reference<XResourceId> xResource1 (aResources1[nIndex]); - const Reference<XResourceId> xResource2 (aResources2[nIndex]); - if (xResource1.is() && xResource2.is()) - { - if (xResource1->compareTo(xResource2) != 0) - return false; - } - else if (xResource1.is() != xResource2.is()) - { - return false; - } - } - - return true; + return std::equal(aResources1.begin(), aResources1.end(), aResources2.begin(), aResources2.end(), + [](const Reference<XResourceId>& a, const Reference<XResourceId>& b) { + if (a.is() && b.is()) + return a->compareTo(b) == 0; + return a.is() == b.is(); + }); } } } // end of namespace sd::framework diff --git a/sd/source/ui/framework/configuration/ConfigurationClassifier.cxx b/sd/source/ui/framework/configuration/ConfigurationClassifier.cxx index 9bd9e19efa76..c39adf26d126 100644 --- a/sd/source/ui/framework/configuration/ConfigurationClassifier.cxx +++ b/sd/source/ui/framework/configuration/ConfigurationClassifier.cxx @@ -89,39 +89,31 @@ void ConfigurationClassifier::ClassifyResources ( ResourceIdVector& rS2minusS1, ResourceIdVector& rS1andS2) { - // Get arrays from the sequences for faster iteration. - const Reference<XResourceId>* aA1 = rS1.getConstArray(); - const Reference<XResourceId>* aA2 = rS2.getConstArray(); - sal_Int32 nL1 (rS1.getLength()); - sal_Int32 nL2 (rS2.getLength()); - // Find all elements in rS1 and place them in rS1minusS2 or rS1andS2 // depending on whether they are in rS2 or not. - for (sal_Int32 i=0; i<nL1; ++i) + for (const Reference<XResourceId>& rA1 : rS1) { - bool bFound (false); - for (sal_Int32 j=0; j<nL2 && !bFound; ++j) - if (aA1[i]->getResourceURL() == aA2[j]->getResourceURL()) - bFound = true; + bool bFound = std::any_of(rS2.begin(), rS2.end(), + [&rA1](const Reference<XResourceId>& rA2) { + return rA1->getResourceURL() == rA2->getResourceURL(); }); if (bFound) - rS1andS2.push_back(aA1[i]); + rS1andS2.push_back(rA1); else - rS1minusS2.push_back(aA1[i]); + rS1minusS2.push_back(rA1); } // Find all elements in rS2 that are not in rS1. The elements that are // in both rS1 and rS2 have been handled above and are therefore ignored // here. - for (sal_Int32 j=0; j<nL2; ++j) + for (const Reference<XResourceId>& rA2 : rS2) { - bool bFound (false); - for (sal_Int32 i=0; i<nL1 && !bFound; ++i) - if (aA2[j]->getResourceURL() == aA1[i]->getResourceURL()) - bFound = true; + bool bFound = std::any_of(rS1.begin(), rS1.end(), + [&rA2](const Reference<XResourceId>& rA1) { + return rA2->getResourceURL() == rA1->getResourceURL(); }); if ( ! bFound) - rS2minusS1.push_back(aA2[j]); + rS2minusS1.push_back(rA2); } } @@ -146,12 +138,11 @@ void ConfigurationClassifier::CopyResources ( SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying " << FrameworkHelper::ResourceIdToString(rxResource)); - const Reference<XResourceId>* aA = aBoundResources.getConstArray(); - for (sal_Int32 i=0; i<nL; ++i) + for (const Reference<XResourceId>& rBoundResource : aBoundResources) { - rTarget.push_back(aA[i]); + rTarget.push_back(rBoundResource); SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying " << - FrameworkHelper::ResourceIdToString(aA[i])); + FrameworkHelper::ResourceIdToString(rBoundResource)); } } } diff --git a/sd/source/ui/framework/configuration/ConfigurationController.cxx b/sd/source/ui/framework/configuration/ConfigurationController.cxx index 9e8fb6fadeee..a78f18f1f2b1 100644 --- a/sd/source/ui/framework/configuration/ConfigurationController.cxx +++ b/sd/source/ui/framework/configuration/ConfigurationController.cxx @@ -259,17 +259,17 @@ void SAL_CALL ConfigurationController::requestResourceActivation ( rxResourceId->getResourceTypePrefix(), AnchorBindingMode_DIRECT)); - for (sal_Int32 nIndex=0; nIndex<aResourceList.getLength(); ++nIndex) + for (const auto& rResource : aResourceList) { // Do not request the deactivation of the resource for which // this method was called. Doing it would not change the // outcome but would result in unnecessary work. - if (rxResourceId->compareTo(aResourceList[nIndex]) == 0) + if (rxResourceId->compareTo(rResource) == 0) continue; // Request the deactivation of a resource and all resources // linked to it. - requestResourceDeactivation(aResourceList[nIndex]); + requestResourceDeactivation(rResource); } } @@ -299,13 +299,12 @@ void SAL_CALL ConfigurationController::requestResourceDeactivation ( rxResourceId, OUString(), AnchorBindingMode_DIRECT)); - const sal_Int32 nCount (aLinkedResources.getLength()); - for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex) + for (const auto& rLinkedResource : aLinkedResources) { // We do not add deactivation requests directly but call this // method recursively, so that when one time there are resources // linked to linked resources, these are handled correctly, too. - requestResourceDeactivation(aLinkedResources[nIndex]); + requestResourceDeactivation(rLinkedResource); } // Add a deactivation request for the specified resource. diff --git a/sd/source/ui/framework/configuration/ResourceId.cxx b/sd/source/ui/framework/configuration/ResourceId.cxx index 78090fe121ac..63144754cba4 100644 --- a/sd/source/ui/framework/configuration/ResourceId.cxx +++ b/sd/source/ui/framework/configuration/ResourceId.cxx @@ -96,8 +96,7 @@ ResourceId::ResourceId ( { maResourceURLs[0] = rsResourceURL; maResourceURLs[1] = rsFirstAnchorURL; - for (sal_Int32 nIndex=0; nIndex<rAnchorURLs.getLength(); ++nIndex) - maResourceURLs[nIndex+2] = rAnchorURLs[nIndex]; + std::copy(rAnchorURLs.begin(), rAnchorURLs.end(), std::next(maResourceURLs.begin(), 2)); ParseResourceURL(); } @@ -360,25 +359,21 @@ Reference<XResourceId> SAL_CALL void SAL_CALL ResourceId::initialize (const Sequence<Any>& aArguments) { - sal_uInt32 nCount (aArguments.getLength()); - for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex) + for (const auto& rArgument : aArguments) { OUString sResourceURL; - if (aArguments[nIndex] >>= sResourceURL) + if (rArgument >>= sResourceURL) maResourceURLs.push_back(sResourceURL); else { Reference<XResourceId> xAnchor; - if (aArguments[nIndex] >>= xAnchor) + if (rArgument >>= xAnchor) { if (xAnchor.is()) { maResourceURLs.push_back(xAnchor->getResourceURL()); Sequence<OUString> aAnchorURLs (xAnchor->getAnchorURLs()); - for (sal_Int32 nURLIndex=0; nURLIndex<aAnchorURLs.getLength(); ++nURLIndex) - { - maResourceURLs.push_back(aAnchorURLs[nURLIndex]); - } + std::copy(aAnchorURLs.begin(), aAnchorURLs.end(), std::back_inserter(maResourceURLs)); } } } diff --git a/sd/source/ui/framework/factories/ViewShellWrapper.cxx b/sd/source/ui/framework/factories/ViewShellWrapper.cxx index 2055867dfd36..95557819e8c7 100644 --- a/sd/source/ui/framework/factories/ViewShellWrapper.cxx +++ b/sd/source/ui/framework/factories/ViewShellWrapper.cxx @@ -117,10 +117,9 @@ sal_Bool SAL_CALL ViewShellWrapper::select( const css::uno::Any& aSelection ) rSelector.DeselectAllPages(); Sequence<Reference<drawing::XDrawPage> > xPages; aSelection >>= xPages; - const sal_uInt32 nCount = xPages.getLength(); - for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex) + for (const auto& rPage : xPages) { - Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY); + Reference<beans::XPropertySet> xSet (rPage, UNO_QUERY); if (xSet.is()) { try diff --git a/sd/source/ui/framework/tools/FrameworkHelper.cxx b/sd/source/ui/framework/tools/FrameworkHelper.cxx index e3826d01c041..830be7136bba 100644 --- a/sd/source/ui/framework/tools/FrameworkHelper.cxx +++ b/sd/source/ui/framework/tools/FrameworkHelper.cxx @@ -753,10 +753,10 @@ OUString FrameworkHelper::ResourceIdToString (const Reference<XResourceId>& rxRe if (rxResourceId->hasAnchor()) { Sequence<OUString> aAnchorURLs (rxResourceId->getAnchorURLs()); - for (sal_Int32 nIndex=0; nIndex < aAnchorURLs.getLength(); ++nIndex) + for (const auto& rAnchorURL : aAnchorURLs) { sString.append(" | "); - sString.append(aAnchorURLs[nIndex]); + sString.append(rAnchorURL); } } } |