sw/source/core/doc/docsort.cxx | 48 +++++++++++------------- sw/source/core/doc/gctable.cxx | 79 ++++++++++++++++++++-------------------- sw/source/core/doc/notxtfrm.cxx | 10 ++--- sw/source/core/doc/number.cxx | 2 - 4 files changed, 68 insertions(+), 71 deletions(-)
New commits: commit 2902cdc173604068abba540118b30d97ddc6b38d Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sun Mar 1 00:23:28 2015 +0100 Use more proper integer types and range-for loops Change-Id: I6c1b6697e984dd39b70dace8568eda41b346e685 diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index ac07c64..01cc39d 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -295,9 +295,8 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) const SwPosition *pStart = rPaM.Start(), *pEnd = rPaM.End(); // Set index to the Selection's start - for ( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n ) + for ( const auto *pFmt : *GetSpzFrmFmts() ) { - const SwFrmFmt *const pFmt = (*GetSpzFrmFmts())[n]; SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor(); SwPosition const*const pAPos = pAnchor->GetCntntAnchor(); @@ -496,7 +495,7 @@ bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) if( !getIDocumentRedlineAccess().IsIgnoreRedline() && !getIDocumentRedlineAccess().GetRedlineTbl().empty() ) getIDocumentRedlineAccess().DeleteRedline( *pTblNd, true, USHRT_MAX ); - sal_uInt16 nStart = 0; + _FndLines::size_type nStart = 0; if( pTblNd->GetTable().GetRowsToRepeat() > 0 && rOpt.eDirection == SRT_ROWS ) { // Uppermost selected Cell @@ -561,9 +560,7 @@ bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) SwSortBoxElements aSortList; // When sorting, do not include the first row if the HeaderLine is repeated - sal_uInt16 i; - - for( i = nStart; i < nCount; ++i) + for( sal_uInt16 i = static_cast<sal_uInt16>(nStart); i < nCount; ++i) { SwSortBoxElement* pEle = new SwSortBoxElement( i ); aSortList.insert(pEle); @@ -571,7 +568,7 @@ bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) // Move after Sorting SwMovedBoxes aMovedList; - i = 0; + sal_uInt16 i = 0; for (SwSortBoxElements::const_iterator it = aSortList.begin(); it != aSortList.end(); ++i, ++it) { @@ -781,9 +778,9 @@ FlatFndBox::~FlatFndBox() bool FlatFndBox::CheckLineSymmetry(const _FndBox& rBox) { const _FndLines &rLines = rBox.GetLines(); - sal_uInt16 nBoxes(0); + _FndBoxes::size_type nBoxes {0}; - for(sal_uInt16 i=0; i < rLines.size(); ++i) + for(_FndLines::size_type i=0; i < rLines.size(); ++i) { const _FndLine* pLn = &rLines[i]; const _FndBoxes& rBoxes = pLn->GetBoxes(); @@ -803,9 +800,9 @@ bool FlatFndBox::CheckLineSymmetry(const _FndBox& rBox) bool FlatFndBox::CheckBoxSymmetry(const _FndLine& rLn) { const _FndBoxes &rBoxes = rLn.GetBoxes(); - sal_uInt16 nLines(0); + _FndLines::size_type nLines {0}; - for(sal_uInt16 i=0; i < rBoxes.size(); ++i) + for(_FndBoxes::size_type i=0; i < rBoxes.size(); ++i) { _FndBox const*const pBox = &rBoxes[i]; const _FndLines& rLines = pBox->GetLines(); @@ -830,15 +827,14 @@ sal_uInt16 FlatFndBox::GetColCount(const _FndBox& rBox) return 1; sal_uInt16 nSum = 0; - for( sal_uInt16 i=0; i < rLines.size(); ++i ) + for( const auto &rLine : rLines ) { // The Boxes of a Line sal_uInt16 nCount = 0; - const _FndBoxes& rBoxes = rLines[i].GetBoxes(); - for( sal_uInt16 j=0; j < rBoxes.size(); ++j ) + const _FndBoxes& rBoxes = rLine.GetBoxes(); + for( const auto &rB : rBoxes ) // Iterate recursively over the Lines - nCount += (rBoxes[j].GetLines().size()) - ? GetColCount(rBoxes[j]) : 1; + nCount += rB.GetLines().empty() ? 1 : GetColCount(rB); if( nSum < nCount ) nSum = nCount; @@ -854,14 +850,14 @@ sal_uInt16 FlatFndBox::GetRowCount(const _FndBox& rBox) return 1; sal_uInt16 nLines = 0; - for(sal_uInt16 i=0; i < rLines.size(); ++i) + for(const auto &rLine : rLines ) { // The Boxes of a Line - const _FndBoxes& rBoxes = rLines[i].GetBoxes(); + const _FndBoxes& rBoxes = rLine.GetBoxes(); sal_uInt16 nLn = 1; - for(sal_uInt16 j=0; j < rBoxes.size(); ++j) - if (rBoxes[j].GetLines().size()) + for(const auto &rB : rBoxes) + if (rB.GetLines().size()) // Iterate recursively over the Lines - nLn = std::max(GetRowCount(rBoxes[j]), nLn); + nLn = std::max(GetRowCount(rB), nLn); nLines = nLines + nLn; } @@ -876,17 +872,17 @@ void FlatFndBox::FillFlat(const _FndBox& rBox, bool bLastBox) // Iterate over Lines sal_uInt16 nOldRow = nRow; - for( sal_uInt16 i=0; i < rLines.size(); ++i ) + for( const auto &rLine : rLines ) { // The Boxes of a Line - const _FndBoxes& rBoxes = rLines[i].GetBoxes(); + const _FndBoxes& rBoxes = rLine.GetBoxes(); sal_uInt16 nOldCol = nCol; - for( sal_uInt16 j = 0; j < rBoxes.size(); ++j ) + for( _FndBoxes::size_type j = 0; j < rBoxes.size(); ++j ) { // Check the Box if it's an atomic one const _FndBox *const pBox = &rBoxes[j]; - if( !pBox->GetLines().size() ) + if( pBox->GetLines().empty() ) { // save it sal_uInt16 nOff = nRow * nCols + nCol; @@ -916,7 +912,7 @@ void FlatFndBox::FillFlat(const _FndBox& rBox, bool bLastBox) else { // Iterate recursively over the Lines of a Box - FillFlat( *pBox, ( j == rBoxes.size()-1 ) ); + FillFlat( *pBox, ( j+1 == rBoxes.size() ) ); } nCol++; } diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index d072d80..03e62ca 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -341,7 +341,7 @@ void SwNumFmt::UpdateNumNodes( SwDoc* pDoc ) { bool bDocIsModified = pDoc->getIDocumentState().IsModified(); bool bFnd = false; - for( sal_uInt16 n = pDoc->GetNumRuleTbl().size(); !bFnd && n; ) + for( SwNumRuleTbl::size_type n = pDoc->GetNumRuleTbl().size(); !bFnd && n; ) { const SwNumRule* pRule = pDoc->GetNumRuleTbl()[ --n ]; for( sal_uInt8 i = 0; i < MAXLEVEL; ++i ) commit f6a42d648e4786ddfcdb9c1f1636a2dea9bceb5f Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Tue Feb 24 22:39:02 2015 +0100 Use more proper integer types and range-for loops Change-Id: Iea85454339b79bd65bdd0f340bd86359370cd5f6 diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index 3b86993..4c6537e 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -117,7 +117,7 @@ static void lcl_PaintReplacement( const SwRect &rRect, const OUString &rText, if ( rURL.GetMap() ) { ImageMap *pMap = (ImageMap*)rURL.GetMap(); - for( sal_uInt16 i = 0; i < pMap->GetIMapObjectCount(); i++ ) + for( size_t i = 0; i < pMap->GetIMapObjectCount(); ++i ) { IMapObject *pObj = pMap->GetIMapObject( i ); if( rSh.GetDoc()->IsVisitedURL( pObj->GetURL() ) ) @@ -190,9 +190,9 @@ static void lcl_ClearArea( const SwFrm &rFrm, if(!bDone) { - for( sal_uInt16 i = 0; i < aRegion.size(); ++i ) + for( const auto &rRegion : aRegion ) { - ::DrawGraphic( pItem, &rOut, aOrigRect, aRegion[i] ); + ::DrawGraphic( pItem, &rOut, aOrigRect, rRegion ); } } } @@ -201,8 +201,8 @@ static void lcl_ClearArea( const SwFrm &rFrm, rOut.Push( PushFlags::FILLCOLOR|PushFlags::LINECOLOR ); rOut.SetFillColor( rFrm.getRootFrm()->GetCurrShell()->Imp()->GetRetoucheColor()); rOut.SetLineColor(); - for( sal_uInt16 i = 0; i < aRegion.size(); ++i ) - rOut.DrawRect( aRegion[i].SVRect() ); + for( const auto &rRegion : aRegion ) + rOut.DrawRect( rRegion.SVRect() ); rOut.Pop(); } } commit b86bdab9916e18c7b4c024882535f64129cd4a68 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Tue Feb 24 20:20:34 2015 +0100 Use more proper integer types and simplify loops Change-Id: Iba85b958c01c7bf6079180973379d4b7261a636e diff --git a/sw/source/core/doc/gctable.cxx b/sw/source/core/doc/gctable.cxx index 291a003..7e52a67 100644 --- a/sw/source/core/doc/gctable.cxx +++ b/sw/source/core/doc/gctable.cxx @@ -54,21 +54,19 @@ static bool lcl_GCBorder_ChkBoxBrd_L( const SwTableLine* pLine, _SwGCBorder_BoxB static bool lcl_GCBorder_ChkBoxBrd_B( const SwTableBox* pBox, _SwGCBorder_BoxBrd* pPara ) { - bool bRet = true; if( !pBox->GetTabLines().empty() ) { - for( sal_uInt16 n = 0, nLines = pBox->GetTabLines().size(); - n < nLines && bRet; ++n ) + for( auto pLine : pBox->GetTabLines() ) { - const SwTableLine* pLine = pBox->GetTabLines()[ n ]; - bRet = lcl_GCBorder_ChkBoxBrd_L( pLine, pPara ); + if (!lcl_GCBorder_ChkBoxBrd_L( pLine, pPara )) + { + return false; + } } + return true; } - else - { - bRet = pPara->CheckLeftBorderOfFormat( *pBox->GetFrmFmt() ); - } - return bRet; + + return pPara->CheckLeftBorderOfFormat( *pBox->GetFrmFmt() ); } static void lcl_GCBorder_GetLastBox_B( const SwTableBox* pBox, SwTableBoxes* pPara ); @@ -94,10 +92,10 @@ static void lcl_GCBorder_GetLastBox_B( const SwTableBox* pBox, SwTableBoxes* pPa // Find the "end" of the passed BorderLine. Returns the "Layout"Pos! static sal_uInt16 lcl_FindEndPosOfBorder( const SwCollectTblLineBoxes& rCollTLB, - const SvxBorderLine& rBrdLn, sal_uInt16& rStt, bool bTop ) + const SvxBorderLine& rBrdLn, size_t& rStt, bool bTop ) { sal_uInt16 nPos, nLastPos = 0; - for( sal_uInt16 nEnd = rCollTLB.Count(); rStt < nEnd; ++rStt ) + for( size_t nEnd = rCollTLB.Count(); rStt < nEnd; ++rStt ) { const SfxPoolItem* pItem; const SvxBorderLine* pBrd; @@ -122,7 +120,7 @@ static inline const SvxBorderLine* lcl_GCBorder_GetBorder( const SwTableBox& rBo } static void lcl_GCBorder_DelBorder( const SwCollectTblLineBoxes& rCollTLB, - sal_uInt16& rStt, bool bTop, + size_t& rStt, bool bTop, const SvxBorderLine& rLine, const SfxPoolItem* pItem, sal_uInt16 nEndPos, @@ -169,7 +167,7 @@ void sw_GC_Line_Border( const SwTableLine* pLine, _SwGCLineBorder* pGCPara ) const SvxBorderLine* pBrd; const SfxPoolItem* pItem; const SwTableBoxes& rBoxes = pLine->GetTabBoxes(); - for( sal_uInt16 n = 0, nBoxes = rBoxes.size() - 1; n < nBoxes; ++n ) + for( SwTableBoxes::size_type n = 0, nBoxes = rBoxes.size() - 1; n < nBoxes; ++n ) { SwTableBoxes aBoxes; { @@ -180,7 +178,7 @@ void sw_GC_Line_Border( const SwTableLine* pLine, _SwGCLineBorder* pGCPara ) lcl_GCBorder_GetLastBox_B( pBox, &aBoxes ); } - for( sal_uInt16 i = aBoxes.size(); i; ) + for( SwTableBoxes::size_type i = aBoxes.size(); i; ) { SwTableBox* pBox; if( SfxItemState::SET == (pBox = aBoxes[ --i ])->GetFrmFmt()-> @@ -218,12 +216,15 @@ void sw_GC_Line_Border( const SwTableLine* pLine, _SwGCLineBorder* pGCPara ) sw_Line_CollectBox( pNextLine, &aTop ); // remove all "duplicated" Lines that are the same - sal_uInt16 nBtmPos, nTopPos, - nSttBtm = 0, nSttTop = 0, - nEndBtm = aBottom.Count(), nEndTop = aTop.Count(); + sal_uInt16 nBtmPos, nTopPos; + + size_t nSttBtm {0}; + size_t nSttTop {0}; + const size_t nEndBtm {aBottom.Count()}; + const size_t nEndTop {aTop.Count()}; - const SwTableBox *pBtmBox = &aBottom.GetBox( nSttBtm++, &nBtmPos ), - *pTopBox = &aTop.GetBox( nSttTop++, &nTopPos ); + const SwTableBox *pBtmBox = &aBottom.GetBox( nSttBtm++, &nBtmPos ); + const SwTableBox *pTopBox = &aTop.GetBox( nSttTop++, &nTopPos ); const SfxPoolItem *pBtmItem = 0, *pTopItem = 0; const SvxBorderLine *pBtmLine(0), *pTopLine(0); bool bGetTopItem = true, bGetBtmItem = true; @@ -237,7 +238,8 @@ void sw_GC_Line_Border( const SwTableLine* pLine, _SwGCLineBorder* pGCPara ) if( pTopLine && pBtmLine && *pTopLine == *pBtmLine ) { // We can remove one, but which one? - sal_uInt16 nSavSttBtm = nSttBtm, nSavSttTop = nSttTop; + const size_t nSavSttBtm {nSttBtm}; + const size_t nSavSttTop {nSttTop}; sal_uInt16 nBtmEndPos = ::lcl_FindEndPosOfBorder( aBottom, *pTopLine, nSttBtm, false ); if( !nBtmEndPos ) nBtmEndPos = nBtmPos; @@ -331,13 +333,12 @@ static bool lcl_MergeGCLine(SwTableLine* pLine, _GCLinePara* pPara); static bool lcl_MergeGCBox(SwTableBox* pTblBox, _GCLinePara* pPara) { - sal_uInt16 n, nLen = pTblBox->GetTabLines().size(); - if( nLen ) + if( !pTblBox->GetTabLines().empty() ) { // ATTENTION: The Line count can change! _GCLinePara aPara( pTblBox->GetTabLines(), pPara ); - for( n = 0; n < pTblBox->GetTabLines().size() && - lcl_MergeGCLine( pTblBox->GetTabLines()[n], &aPara ); + for( SwTableLines::size_type n = 0; + n < pTblBox->GetTabLines().size() && lcl_MergeGCLine( pTblBox->GetTabLines()[n], &aPara ); ++n ) ; @@ -347,8 +348,8 @@ static bool lcl_MergeGCBox(SwTableBox* pTblBox, _GCLinePara* pPara) SwTableLine* pInsLine = pTblBox->GetUpper(); SwTableLine* pCpyLine = pTblBox->GetTabLines()[0]; SwTableBoxes::iterator it = std::find( pInsLine->GetTabBoxes().begin(), pInsLine->GetTabBoxes().end(), pTblBox ); - for( n = 0; n < pCpyLine->GetTabBoxes().size(); ++n ) - pCpyLine->GetTabBoxes()[n]->SetUpper( pInsLine ); + for( auto pTabBox : pCpyLine->GetTabBoxes() ) + pTabBox->SetUpper( pInsLine ); // remove the old box from its parent line it = pInsLine->GetTabBoxes().erase( it ); @@ -366,10 +367,10 @@ static bool lcl_MergeGCBox(SwTableBox* pTblBox, _GCLinePara* pPara) static bool lcl_MergeGCLine(SwTableLine* pLn, _GCLinePara* pGCPara) { - sal_uInt16 nLen = pLn->GetTabBoxes().size(); - if( nLen ) + SwTableBoxes::size_type nBoxes = pLn->GetTabBoxes().size(); + if( nBoxes ) { - while( 1 == nLen ) + while( 1 == nBoxes ) { // We have a Box with Lines SwTableBox* pBox = pLn->GetTabBoxes().front(); @@ -381,7 +382,7 @@ static bool lcl_MergeGCLine(SwTableLine* pLn, _GCLinePara* pGCPara) // pLine turns into the current Line (that is rpLine), the rest is moved // into the LinesArray past the current one. // The LinesArray is in pPara! - nLen = pBox->GetTabLines().size(); + SwTableLines::size_type nLines = pBox->GetTabLines().size(); SwTableLines& rLns = *pGCPara->pLns; sal_uInt16 nInsPos = rLns.GetPos( pLn ); @@ -399,26 +400,26 @@ static bool lcl_MergeGCLine(SwTableLine* pLn, _GCLinePara* pGCPara) RES_BACKGROUND, true, &pItem )) { SwTableLines& rBoxLns = pBox->GetTabLines(); - for( sal_uInt16 nLns = 0; nLns < nLen; ++nLns ) - if( SfxItemState::SET != rBoxLns[ nLns ]->GetFrmFmt()-> + for( auto pBoxLine : rBoxLns ) + if( SfxItemState::SET != pBoxLine->GetFrmFmt()-> GetItemState( RES_BACKGROUND, true )) - pGCPara->pShareFmts->SetAttr( *rBoxLns[ nLns ], *pItem ); + pGCPara->pShareFmts->SetAttr( *pBoxLine, *pItem ); } - pBox->GetTabLines().erase( pBox->GetTabLines().begin(), pBox->GetTabLines().begin() + nLen ); // Remove Lines from the array + pBox->GetTabLines().erase( pBox->GetTabLines().begin(), pBox->GetTabLines().begin() + nLines ); // Remove Lines from the array delete pLn; // Set the dependency anew - while( nLen-- ) + while( nLines-- ) rLns[ nInsPos++ ]->SetUpper( pUpper ); pLn = pLine; // and set up anew - nLen = pLn->GetTabBoxes().size(); + nBoxes = pLn->GetTabBoxes().size(); } // ATTENTION: The number of boxes can change! - for( nLen = 0; nLen < pLn->GetTabBoxes().size(); ++nLen ) + for( SwTableBoxes::size_type nLen = 0; nLen < pLn->GetTabBoxes().size(); ++nLen ) if( !lcl_MergeGCBox( pLn->GetTabBoxes()[nLen], pGCPara )) --nLen; } @@ -432,7 +433,7 @@ void SwTable::GCLines() _GCLinePara aPara( GetTabLines() ); SwShareBoxFmts aShareFmts; aPara.pShareFmts = &aShareFmts; - for( sal_uInt16 n = 0; n < GetTabLines().size() && + for( SwTableLines::size_type n = 0; n < GetTabLines().size() && lcl_MergeGCLine( GetTabLines()[n], &aPara ); ++n ) ; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits