editeng/source/uno/unotext2.cxx | 57 ++++++------ sd/inc/CustomAnimationEffect.hxx | 4 sd/source/core/CustomAnimationEffect.cxx | 146 ++++++++++++++++++++++--------- 3 files changed, 139 insertions(+), 68 deletions(-)
New commits: commit 6d9cc6bf2fc9226f9cd0febdf8720fb8a02ae6df Author: Serge Krot <serge.k...@cib.de> AuthorDate: Thu Jan 2 12:24:27 2020 +0100 Commit: Thorsten Behrens <thorsten.behr...@cib.de> CommitDate: Tue Apr 28 01:06:14 2020 +0200 tdf#129708 speed-up: reuse enumeration for each effect Conflicts: editeng/source/uno/unotext2.cxx sd/source/core/CustomAnimationEffect.cxx Change-Id: I336278c5a9eec75a2a71fe4d04d2029a5a08e6a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86102 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92649 Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx index 43d803c3d340..45f57c4ccd9f 100644 --- a/editeng/source/uno/unotext2.cxx +++ b/editeng/source/uno/unotext2.cxx @@ -46,40 +46,41 @@ SvxUnoTextContentEnumeration::SvxUnoTextContentEnumeration( const SvxUnoTextBase if( mrText.GetEditSource() ) mpEditSource = mrText.GetEditSource()->Clone(); mnNextParagraph = 0; - for( sal_Int32 currentPara = 0; currentPara < mrText.GetEditSource()->GetTextForwarder()->GetParagraphCount(); currentPara++ ) + + const SvxTextForwarder* pTextForwarder = mrText.GetEditSource()->GetTextForwarder(); + const sal_Int32 maxParaIndex = std::min( rSel.nEndPara + 1, pTextForwarder->GetParagraphCount() ); + + for( sal_Int32 currentPara = rSel.nStartPara; currentPara < maxParaIndex; currentPara++ ) { - if( currentPara>=rSel.nStartPara && currentPara<=rSel.nEndPara ) + const SvxUnoTextRangeBaseVec& rRanges( mpEditSource->getRanges() ); + SvxUnoTextContent* pContent = nullptr; + sal_Int32 nStartPos = 0; + sal_Int32 nEndPos = pTextForwarder->GetTextLen( currentPara ); + if( currentPara == rSel.nStartPara ) + nStartPos = std::max(nStartPos, rSel.nStartPos); + if( currentPara == rSel.nEndPara ) + nEndPos = std::min(nEndPos, rSel.nEndPos); + ESelection aCurrentParaSel( currentPara, nStartPos, currentPara, nEndPos ); + for (auto const& elemRange : rRanges) { - const SvxUnoTextRangeBaseVec& rRanges( mpEditSource->getRanges() ); - SvxUnoTextContent* pContent = nullptr; - sal_Int32 nStartPos = 0; - sal_Int32 nEndPos = mrText.GetEditSource()->GetTextForwarder()->GetTextLen( currentPara ); - if( currentPara == rSel.nStartPara ) - nStartPos = std::max(nStartPos, rSel.nStartPos); - if( currentPara == rSel.nEndPara ) - nEndPos = std::min(nEndPos, rSel.nEndPos); - ESelection aCurrentParaSel = ESelection( currentPara, nStartPos, currentPara, nEndPos ); - for (auto const& elemRange : rRanges) + if (pContent) + break; + SvxUnoTextContent* pIterContent = dynamic_cast< SvxUnoTextContent* >( elemRange ); + if( pIterContent && (pIterContent->mnParagraph == currentPara) ) { - if (pContent) - break; - SvxUnoTextContent* pIterContent = dynamic_cast< SvxUnoTextContent* >( elemRange ); - if( pIterContent && (pIterContent->mnParagraph == currentPara) ) + ESelection aIterSel = pIterContent->GetSelection(); + if( aIterSel == aCurrentParaSel ) { - ESelection aIterSel = pIterContent->GetSelection(); - if( aIterSel == aCurrentParaSel ) - { - pContent = pIterContent; - maContents.emplace_back(pContent ); - } + pContent = pIterContent; + maContents.emplace_back(pContent ); } } - if( pContent == nullptr ) - { - pContent = new SvxUnoTextContent( mrText, currentPara ); - pContent->SetSelection( aCurrentParaSel ); - maContents.emplace_back(pContent ); - } + } + if( pContent == nullptr ) + { + pContent = new SvxUnoTextContent( mrText, currentPara ); + pContent->SetSelection( aCurrentParaSel ); + maContents.emplace_back(pContent ); } } } diff --git a/sd/inc/CustomAnimationEffect.hxx b/sd/inc/CustomAnimationEffect.hxx index 91dc355b8cc7..d878175cb445 100644 --- a/sd/inc/CustomAnimationEffect.hxx +++ b/sd/inc/CustomAnimationEffect.hxx @@ -143,7 +143,7 @@ public: SAL_DLLPRIVATE OUString getPath() const; SAL_DLLPRIVATE void setPath( const OUString& rPath ); - SAL_DLLPRIVATE bool checkForText(); + SAL_DLLPRIVATE bool checkForText( const std::vector<sal_Int32>* paragraphNumberingLevel = nullptr ); SAL_DLLPRIVATE bool calculateIterateDuration(); SAL_DLLPRIVATE void setAudio( const css::uno::Reference< css::animations::XAudio >& xAudio ); @@ -331,6 +331,8 @@ protected: SAL_DLLPRIVATE void updateTextGroups(); + SAL_DLLPRIVATE bool getParagraphNumberingLevels( const css::uno::Reference< css::drawing::XShape >& xShape, std::vector< sal_Int32 >& rParagraphNumberingLevel ); + protected: css::uno::Reference< css::animations::XTimeContainer > mxSequenceRoot; EffectSequence maEffects; diff --git a/sd/source/core/CustomAnimationEffect.cxx b/sd/source/core/CustomAnimationEffect.cxx index 0b18595be1de..f9208dfd87c0 100644 --- a/sd/source/core/CustomAnimationEffect.cxx +++ b/sd/source/core/CustomAnimationEffect.cxx @@ -63,6 +63,7 @@ #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <algorithm> +#include <numeric> #include <deque> #include <cppuhelper/implbase.hxx> @@ -527,7 +528,7 @@ void CustomAnimationEffect::setGroupId( sal_Int32 nGroupId ) /** checks if the text for this effect has changed and updates internal flags. returns true if something changed. */ -bool CustomAnimationEffect::checkForText() +bool CustomAnimationEffect::checkForText( const std::vector<sal_Int32>* paragraphNumberingLevel ) { bool bChange = false; @@ -544,36 +545,52 @@ bool CustomAnimationEffect::checkForText() // get paragraph if( xText.is() ) { - Reference< XEnumerationAccess > xEA( xText, UNO_QUERY ); - if( xEA.is() ) + sal_Int32 nPara = aParaTarget.Paragraph; + + bool bHasText = false; + sal_Int32 nParaDepth = 0; + + if ( paragraphNumberingLevel ) { - Reference< XEnumeration > xEnumeration( xEA->createEnumeration(), UNO_QUERY ); - if( xEnumeration.is() ) + bHasText = !paragraphNumberingLevel->empty(); + if (nPara >= 0 && static_cast<size_t>(nPara) < paragraphNumberingLevel->size()) + nParaDepth = paragraphNumberingLevel->at(nPara); + } + else + { + Reference< XEnumerationAccess > xEA( xText, UNO_QUERY ); + if( xEA.is() ) { - bool bHasText = xEnumeration->hasMoreElements(); - bChange |= bHasText != mbHasText; - mbHasText = bHasText; - - sal_Int32 nPara = aParaTarget.Paragraph; + Reference< XEnumeration > xEnumeration = xEA->createEnumeration(); + if( xEnumeration.is() ) + { + bHasText = xEnumeration->hasMoreElements(); - while( xEnumeration->hasMoreElements() && nPara-- ) - xEnumeration->nextElement(); + while( xEnumeration->hasMoreElements() && nPara-- ) + xEnumeration->nextElement(); - if( xEnumeration->hasMoreElements() ) - { - Reference< XPropertySet > xParaSet; - xEnumeration->nextElement() >>= xParaSet; - if( xParaSet.is() ) + if( xEnumeration->hasMoreElements() ) { - sal_Int32 nParaDepth = 0; - const OUString strNumberingLevel( "NumberingLevel" ); - xParaSet->getPropertyValue( strNumberingLevel ) >>= nParaDepth; - bChange |= nParaDepth != mnParaDepth; - mnParaDepth = nParaDepth; + Reference< XPropertySet > xParaSet; + xEnumeration->nextElement() >>= xParaSet; + if( xParaSet.is() ) + { + const OUString strNumberingLevel( "NumberingLevel" ); + xParaSet->getPropertyValue( strNumberingLevel ) >>= nParaDepth; + } } } } } + + if( bHasText ) + { + bChange |= bHasText != mbHasText; + mbHasText = bHasText; + + bChange |= nParaDepth != mnParaDepth; + mnParaDepth = nParaDepth; + } } } else @@ -2143,21 +2160,65 @@ bool EffectSequenceHelper::hasEffect( const css::uno::Reference< css::drawing::X return false; } -void EffectSequenceHelper::insertTextRange( const css::uno::Any& aTarget ) +bool EffectSequenceHelper::getParagraphNumberingLevels( const Reference< XShape >& xShape, std::vector< sal_Int32 >& rParagraphNumberingLevel ) { - bool bChanges = false; + rParagraphNumberingLevel.clear(); + if( !hasEffect( xShape ) ) + return false; + + Reference< XText > xText( xShape, UNO_QUERY ); + if( xText.is() ) + { + Reference< XEnumerationAccess > xEA( xText, UNO_QUERY ); + if( xEA.is() ) + { + Reference< XEnumeration > xEnumeration = xEA->createEnumeration(); + + if( xEnumeration.is() ) + { + for( sal_Int32 index = 0; xEnumeration->hasMoreElements(); index++ ) + { + Reference< XPropertySet > xParaSet; + xEnumeration->nextElement() >>= xParaSet; + + sal_Int32 nParaDepth = 0; + if( xParaSet.is() ) + { + const OUString strNumberingLevel( "NumberingLevel" ); + xParaSet->getPropertyValue( strNumberingLevel ) >>= nParaDepth; + } + + rParagraphNumberingLevel.push_back( nParaDepth ); + } + } + } + } + + return true; +} + +void EffectSequenceHelper::insertTextRange( const css::uno::Any& aTarget ) +{ ParagraphTarget aParaTarget; if( !(aTarget >>= aParaTarget ) ) return; - EffectSequence::iterator aIter( maEffects.begin() ); - while( aIter != maEffects.end() ) - { - if( (*aIter)->getTargetShape() == aParaTarget.Shape ) - bChanges |= (*aIter)->checkForText(); - ++aIter; - } + // get map [paragraph index] -> [NumberingLevel] + // for following reusage inside all animation effects + std::vector< sal_Int32 > paragraphNumberingLevel; + std::vector< sal_Int32 >* paragraphNumberingLevelParam = nullptr; + if ( getParagraphNumberingLevels( aParaTarget.Shape, paragraphNumberingLevel ) ) + paragraphNumberingLevelParam = ¶graphNumberingLevel; + + // update internal flags for each animation effect + const bool bChanges = std::accumulate(maEffects.begin(), maEffects.end(), false, + [&aParaTarget, ¶graphNumberingLevelParam](const bool bCheck, const CustomAnimationEffectPtr& rxEffect) { + bool bRes = bCheck; + if (rxEffect->getTargetShape() == aParaTarget.Shape) + bRes |= rxEffect->checkForText( paragraphNumberingLevelParam ); + return bRes; + }); if( bChanges ) rebuild(); @@ -3214,14 +3275,21 @@ void MainSequence::onTextChanged( const Reference< XShape >& xShape ) void EffectSequenceHelper::onTextChanged( const Reference< XShape >& xShape ) { - bool bChanges = false; - - EffectSequence::iterator aIter; - for( aIter = maEffects.begin(); aIter != maEffects.end(); ++aIter ) - { - if( (*aIter)->getTargetShape() == xShape ) - bChanges |= (*aIter)->checkForText(); - } + // get map [paragraph index] -> [NumberingLevel] + // for following reusage inside all animation effects + std::vector< sal_Int32 > paragraphNumberingLevel; + std::vector< sal_Int32 >* paragraphNumberingLevelParam = nullptr; + if ( getParagraphNumberingLevels( xShape, paragraphNumberingLevel ) ) + paragraphNumberingLevelParam = ¶graphNumberingLevel; + + // update internal flags for each animation effect + const bool bChanges = std::accumulate(maEffects.begin(), maEffects.end(), false, + [&xShape, ¶graphNumberingLevelParam](const bool bCheck, const CustomAnimationEffectPtr& rxEffect) { + bool bRes = bCheck; + if (rxEffect->getTargetShape() == xShape) + bRes |= rxEffect->checkForText( paragraphNumberingLevelParam ); + return bRes; + }); if( bChanges ) EffectSequenceHelper::implRebuild(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits