tdf#64991 speed up loading large RTL documents
takes load time from 20s to 17s for me
Several loops are very hot, so store the count()/size() value,
instead of calling it on every iteration.
Change-Id: I8c0b01721d27e4335dd613cf276dcdd0103633ce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120945
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx
index 5434e00..f76f152 100644
--- a/sw/source/core/text/itratr.cxx
+++ b/sw/source/core/text/itratr.cxx
@@ -260,6 +260,7 @@ void SwAttrIter::SeekFwd(const sal_Int32 nOldPos, const sal_Int32 nNewPos)
{
SwpHints const*const pHints(m_pTextNode->GetpSwpHints());
SwTextAttr *pTextAttr;
const auto nHintsCount = pHints->Count();
if ( m_nStartIndex ) // If attributes have been opened at all ...
{
@@ -267,7 +268,7 @@ void SwAttrIter::SeekFwd(const sal_Int32 nOldPos, const sal_Int32 nNewPos)
// As long as we've not yet reached the end of EndArray and the
// TextAttribute ends before or at the new position ...
while ((m_nEndIndex < pHints->Count()) &&
while ((m_nEndIndex < nHintsCount) &&
((pTextAttr = pHints->GetSortedByEnd(m_nEndIndex))->GetAnyEnd() <= nNewPos))
{
// Close the TextAttributes, whose StartPos were before or at
@@ -278,7 +279,7 @@ void SwAttrIter::SeekFwd(const sal_Int32 nOldPos, const sal_Int32 nNewPos)
}
else // skip the not opened ends
{
while ((m_nEndIndex < pHints->Count()) &&
while ((m_nEndIndex < nHintsCount) &&
(pHints->GetSortedByEnd(m_nEndIndex)->GetAnyEnd() <= nNewPos))
{
m_nEndIndex++;
@@ -287,7 +288,7 @@ void SwAttrIter::SeekFwd(const sal_Int32 nOldPos, const sal_Int32 nNewPos)
// As long as we've not yet reached the end of EndArray and the
// TextAttribute ends before or at the new position...
while ((m_nStartIndex < pHints->Count()) &&
while ((m_nStartIndex < nHintsCount) &&
((pTextAttr = pHints->Get(m_nStartIndex))->GetStart() <= nNewPos))
{
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index 1ea089b..ee15954 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -860,12 +860,14 @@ namespace sw {
}
if (m_pMerged)
{
while (m_CurrentExtent < m_pMerged->extents.size())
const auto nExtentsSize = m_pMerged->extents.size();
while (m_CurrentExtent < nExtentsSize)
{
sw::Extent const& rExtent(m_pMerged->extents[m_CurrentExtent]);
if (SwpHints const*const pHints = rExtent.pNode->GetpSwpHints())
{
while (m_CurrentHint < pHints->Count())
auto nHintsCount = pHints->Count();
while (m_CurrentHint < nHintsCount)
{
SwTextAttr const*const pHint(pHints->Get(m_CurrentHint));
if (rExtent.nEnd < pHint->GetStart())
@@ -881,7 +883,7 @@ namespace sw {
}
}
++m_CurrentExtent;
if (m_CurrentExtent < m_pMerged->extents.size() &&
if (m_CurrentExtent < nExtentsSize &&
rExtent.pNode != m_pMerged->extents[m_CurrentExtent].pNode)
{
m_CurrentHint = 0; // reset
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index f02b880..b53d1d7 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -710,7 +710,8 @@ lcl_ExportHints(
//search for special text attributes - first some ends
size_t nEndIndex = 0;
sal_Int32 nNextEnd = 0;
while(nEndIndex < pHints->Count() &&
const auto nHintsCount = pHints->Count();
while(nEndIndex < nHintsCount &&
(!pHints->GetSortedByEnd(nEndIndex)->GetEnd() ||
nCurrentIndex >= (nNextEnd = (*pHints->GetSortedByEnd(nEndIndex)->GetEnd()))))
{
@@ -791,7 +792,7 @@ lcl_ExportHints(
// then some starts
size_t nStartIndex = 0;
sal_Int32 nNextStart = 0;
while(nStartIndex < pHints->Count() &&
while(nStartIndex < nHintsCount &&
nCurrentIndex >= (nNextStart = pHints->Get(nStartIndex)->GetStart()))
{
SwTextAttr * const pAttr = pHints->Get(nStartIndex);