sw/source/core/doc/doccorr.cxx | 4 - sw/source/core/doc/docdesc.cxx | 12 +-- sw/source/core/doc/docedt.cxx | 12 +-- sw/source/core/doc/docfld.cxx | 107 ++++++++++++++---------------- sw/source/core/doc/docfly.cxx | 5 - sw/source/core/doc/docfmt.cxx | 30 +++----- sw/source/core/doc/docglbl.cxx | 4 - sw/source/core/doc/doclay.cxx | 61 +++++++---------- sw/source/core/doc/docnew.cxx | 18 +---- sw/source/core/doc/docnum.cxx | 141 ++++++++++++++++++---------------------- sw/source/core/doc/docredln.cxx | 46 ++++++------- sw/source/core/doc/fmtcol.cxx | 32 +++------ 12 files changed, 212 insertions(+), 260 deletions(-)
New commits: commit 949b9dc8ed2f5cdfd6f99531fc4ac2b8c201b145 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 21 16:33:06 2015 +0100 Use more proper types and range-for loops Change-Id: I90b71a5abbca19d9b5eaf2ded2f33b01fb775d3a diff --git a/sw/source/core/doc/fmtcol.cxx b/sw/source/core/doc/fmtcol.cxx index 5124ec4..4d9d28e 100644 --- a/sw/source/core/doc/fmtcol.cxx +++ b/sw/source/core/doc/fmtcol.cxx @@ -565,19 +565,16 @@ SwConditionTxtFmtColl::~SwConditionTxtFmtColl() const SwCollCondition* SwConditionTxtFmtColl::HasCondition( const SwCollCondition& rCond ) const { - const SwCollCondition* pFnd = 0; - sal_uInt16 n; + for( const auto &rFnd : aCondColls ) + if( rFnd == rCond ) + return &rFnd; - for( n = 0; n < aCondColls.size(); ++n ) - if( *( pFnd = &aCondColls[ n ]) == rCond ) - break; - - return n < aCondColls.size() ? pFnd : 0; + return nullptr; } void SwConditionTxtFmtColl::InsertCondition( const SwCollCondition& rCond ) { - for( sal_uInt16 n = 0; n < aCondColls.size(); ++n ) + for( SwFmtCollConditions::size_type n = 0; n < aCondColls.size(); ++n ) if( aCondColls[ n ] == rCond ) { aCondColls.erase( aCondColls.begin() + n ); @@ -592,7 +589,7 @@ void SwConditionTxtFmtColl::InsertCondition( const SwCollCondition& rCond ) bool SwConditionTxtFmtColl::RemoveCondition( const SwCollCondition& rCond ) { bool bRet = false; - for( sal_uInt16 n = 0; n < aCondColls.size(); ++n ) + for( SwFmtCollConditions::size_type n = 0; n < aCondColls.size(); ++n ) if( aCondColls[ n ] == rCond ) { aCondColls.erase( aCondColls.begin() + n ); @@ -607,19 +604,18 @@ void SwConditionTxtFmtColl::SetConditions( const SwFmtCollConditions& rCndClls ) // Copy the Conditions, but first delete the old ones aCondColls.clear(); SwDoc& rDoc = *GetDoc(); - for( sal_uInt16 n = 0; n < rCndClls.size(); ++n ) + for( const auto &rFnd : rCndClls ) { - const SwCollCondition* pFnd = &rCndClls[ n ]; - SwTxtFmtColl* pTmpColl = pFnd->GetTxtFmtColl() - ? rDoc.CopyTxtColl( *pFnd->GetTxtFmtColl() ) + SwTxtFmtColl* pTmpColl = rFnd.GetTxtFmtColl() + ? rDoc.CopyTxtColl( *rFnd.GetTxtFmtColl() ) : 0; SwCollCondition* pNew; - if( USRFLD_EXPRESSION & pFnd->GetCondition() ) - pNew = new SwCollCondition( pTmpColl, pFnd->GetCondition(), - *pFnd->GetFldExpression() ); + if( USRFLD_EXPRESSION & rFnd.GetCondition() ) + pNew = new SwCollCondition( pTmpColl, rFnd.GetCondition(), + *rFnd.GetFldExpression() ); else - pNew = new SwCollCondition( pTmpColl, pFnd->GetCondition(), - pFnd->GetSubCondition() ); + pNew = new SwCollCondition( pTmpColl, rFnd.GetCondition(), + rFnd.GetSubCondition() ); aCondColls.push_back( pNew ); } } commit bf586debd4d8274cff2737f02beac465525328e8 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 21 12:38:54 2015 +0100 Simplify Change-Id: Iabfbe854f97b92127f1118b0982be39c4d0a2b8b diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 6a987a0..8214379 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -566,9 +566,9 @@ static SwTxtNode* lcl_FindOutlineName( const SwOutlineNodes& rOutlNds, const OUS bool bExact ) { SwTxtNode* pSavedNode = nullptr; - for( SwOutlineNodes::size_type n = 0; n < rOutlNds.size(); ++n ) + for( auto pOutlNd : rOutlNds ) { - SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); + SwTxtNode* pTxtNd = pOutlNd->GetTxtNode(); const OUString sTxt( pTxtNd->GetExpandTxt() ); if (sTxt.startsWith(rName)) { @@ -601,22 +601,25 @@ static SwTxtNode* lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& sal_uInt16 nLevelVal[ MAXLEVEL ]; // numbers of all levels memset( nLevelVal, 0, MAXLEVEL * sizeof( nLevelVal[0] )); - sal_uInt8 nLevel = 0; + int nLevel = 0; OUString sName( rName ); while( -1 != nPos ) { sal_uInt16 nVal = 0; - sal_Unicode c; for( sal_Int32 n = 0; n < sNum.getLength(); ++n ) - if( '0' <= ( c = sNum[ n ]) && c <= '9' ) + { + const sal_Unicode c {sNum[ n ]}; + if( '0' <= c && c <= '9' ) { - nVal *= 10; nVal += c - '0'; + nVal *= 10; + nVal += c - '0'; } else if( nLevel ) break; // "almost" valid number else return nullptr; // invalid number! + } if( MAXLEVEL > nLevel ) nLevelVal[ nLevel++ ] = nVal; @@ -626,7 +629,7 @@ static SwTxtNode* lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& sNum = sName.getToken( 0, '.', nPos ); // #i4533# without this check all parts delimited by a dot are treated as outline numbers if(!comphelper::string::isdigitAsciiString(sNum)) - nPos = -1; + break; } rName = sName; // that's the follow-up text @@ -637,32 +640,26 @@ static SwTxtNode* lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& if( rOutlNds.empty() ) return nullptr; - SwTxtNode* pNd; - nPos = 0; // search in the existing outline nodes for the required outline num array - for( ; nPos < (sal_Int32) rOutlNds.size(); ++nPos ) + for( auto pOutlNd : rOutlNds ) { - pNd = rOutlNds[ nPos ]->GetTxtNode(); - const int nLvl = pNd->GetAttrOutlineLevel()-1; - if( nLvl == nLevel - 1) + SwTxtNode* pNd = pOutlNd->GetTxtNode(); + if ( pNd->GetAttrOutlineLevel() == nLevel ) { // #i51089#, #i68289# // Assure, that text node has the correct numbering level. Otherwise, // its number vector will not fit to the searched level. - if ( pNd->GetNum() && - pNd->GetActualListLevel() == ( nLevel - 1 ) ) + if ( pNd->GetNum() && pNd->GetActualListLevel() == nLevel - 1 ) { const SwNodeNum & rNdNum = *(pNd->GetNum()); SwNumberTree::tNumberVector aLevelVal = rNdNum.GetNumberVector(); // now compare with the one searched for - bool bEqual = true; - for( sal_uInt8 n = 0; (n < nLevel) && bEqual; ++n ) - { - bEqual = aLevelVal[n] == nLevelVal[n]; - } - if(bEqual) + for( int n = 0; n < nLevel; ++n ) { - break; + if ( aLevelVal[n] == nLevelVal[n] ) + { + return pNd; + } } } else @@ -676,10 +673,8 @@ static SwTxtNode* lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& } } } - if( nPos >= (sal_Int32) rOutlNds.size() ) - return nullptr; - return rOutlNds[ nPos ]->GetTxtNode(); + return nullptr; } // Add this bullet point: commit 007edeb70409e3ca3c5cdb1b3514e592a9fa5ba0 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 21 10:12:42 2015 +0100 Directly return the needed SwTxtNode* instead of its index Change-Id: Ia5df160a21ff4c6f5f526945c6b90a974a88c011 diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index a89ebce..6a987a0 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -562,10 +562,10 @@ bool SwDoc::MoveOutlinePara( const SwPaM& rPam, short nOffset ) return MoveParagraph( aPam, nOffs, true ); } -static sal_uInt16 lcl_FindOutlineName( const SwOutlineNodes& rOutlNds, const OUString& rName, +static SwTxtNode* lcl_FindOutlineName( const SwOutlineNodes& rOutlNds, const OUString& rName, bool bExact ) { - sal_uInt16 nSavePos = USHRT_MAX; + SwTxtNode* pSavedNode = nullptr; for( SwOutlineNodes::size_type n = 0; n < rOutlNds.size(); ++n ) { SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); @@ -575,21 +575,20 @@ static sal_uInt16 lcl_FindOutlineName( const SwOutlineNodes& rOutlNds, const OUS if (sTxt.getLength() == rName.getLength()) { // Found "exact", set Pos to the Node - nSavePos = n; - break; + return pTxtNd; } - else if( !bExact && USHRT_MAX == nSavePos ) + if( !bExact && !pSavedNode ) { // maybe we just found the text's first part - nSavePos = n; + pSavedNode = pTxtNd; } } } - return nSavePos; + return pSavedNode; } -static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& rName ) +static SwTxtNode* lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& rName ) { // Valid numbers are (always just offsets!): // ([Number]+\.)+ (as a regular expression!) @@ -598,7 +597,7 @@ static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& sal_Int32 nPos = 0; OUString sNum = rName.getToken( 0, '.', nPos ); if( -1 == nPos ) - return USHRT_MAX; // invalid number! + return nullptr; // invalid number! sal_uInt16 nLevelVal[ MAXLEVEL ]; // numbers of all levels memset( nLevelVal, 0, MAXLEVEL * sizeof( nLevelVal[0] )); @@ -617,7 +616,7 @@ static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& else if( nLevel ) break; // "almost" valid number else - return USHRT_MAX; // invalid number! + return nullptr; // invalid number! if( MAXLEVEL > nLevel ) nLevelVal[ nLevel++ ] = nVal; @@ -636,7 +635,7 @@ static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& // Without OutlineNodes searching doesn't pay off // and we save a crash if( rOutlNds.empty() ) - return USHRT_MAX; + return nullptr; SwTxtNode* pNd; nPos = 0; @@ -678,8 +677,9 @@ static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& } } if( nPos >= (sal_Int32) rOutlNds.size() ) - nPos = USHRT_MAX; - return nPos; + return nullptr; + + return rOutlNds[ nPos ]->GetTxtNode(); } // Add this bullet point: @@ -700,10 +700,9 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const // 1. step: via the Number: OUString sName( rName ); - sal_uInt16 nFndPos = ::lcl_FindOutlineNum( rOutlNds, sName ); - if( USHRT_MAX != nFndPos ) + SwTxtNode* pNd = ::lcl_FindOutlineNum( rOutlNds, sName ); + if ( pNd ) { - SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); OUString sExpandedText = pNd->GetExpandTxt(); //#i4533# leading numbers followed by a dot have been remove while //searching for the outline position @@ -720,11 +719,10 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const if( sExpandedText != sName ) { - sal_uInt16 nTmp = ::lcl_FindOutlineName( rOutlNds, sName, true ); - if( USHRT_MAX != nTmp ) // found via the Name + SwTxtNode *pTmpNd = ::lcl_FindOutlineName( rOutlNds, sName, true ); + if ( pTmpNd ) // found via the Name { - nFndPos = nTmp; - pNd = rOutlNds[ nFndPos ]->GetTxtNode(); + pNd = pTmpNd; } } rPos.nNode = *pNd; @@ -732,10 +730,9 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const return true; } - nFndPos = ::lcl_FindOutlineName( rOutlNds, rName, false ); - if( USHRT_MAX != nFndPos ) + pNd = ::lcl_FindOutlineName( rOutlNds, rName, false ); + if ( pNd ) { - SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); rPos.nNode = *pNd; rPos.nContent.Assign( pNd, 0 ); return true; @@ -744,10 +741,9 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const // #i68289# additional search on hyperlink URL without its outline numbering part if ( sName != rName ) { - nFndPos = ::lcl_FindOutlineName( rOutlNds, sName, false ); - if( USHRT_MAX != nFndPos ) + pNd = ::lcl_FindOutlineName( rOutlNds, sName, false ); + if ( pNd ) { - SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); rPos.nNode = *pNd; rPos.nContent.Assign( pNd, 0 ); return true; commit 8d219ce09375535ffbe3ae997549ee944b43117c Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 21 09:39:12 2015 +0100 SwOutlineNodes are already available Change-Id: I384308ebffcdbc6df0ee752339dd49957f7d4bbb diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 77dfbc5..a89ebce 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -562,11 +562,10 @@ bool SwDoc::MoveOutlinePara( const SwPaM& rPam, short nOffset ) return MoveParagraph( aPam, nOffs, true ); } -static sal_uInt16 lcl_FindOutlineName( const SwNodes& rNds, const OUString& rName, +static sal_uInt16 lcl_FindOutlineName( const SwOutlineNodes& rOutlNds, const OUString& rName, bool bExact ) { sal_uInt16 nSavePos = USHRT_MAX; - const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds(); for( SwOutlineNodes::size_type n = 0; n < rOutlNds.size(); ++n ) { SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); @@ -590,7 +589,7 @@ static sal_uInt16 lcl_FindOutlineName( const SwNodes& rNds, const OUString& rNam return nSavePos; } -static sal_uInt16 lcl_FindOutlineNum( const SwNodes& rNds, OUString& rName ) +static sal_uInt16 lcl_FindOutlineNum( const SwOutlineNodes& rOutlNds, OUString& rName ) { // Valid numbers are (always just offsets!): // ([Number]+\.)+ (as a regular expression!) @@ -633,11 +632,12 @@ static sal_uInt16 lcl_FindOutlineNum( const SwNodes& rNds, OUString& rName ) rName = sName; // that's the follow-up text // read all levels, so search the document for this outline - const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds(); + // Without OutlineNodes searching doesn't pay off // and we save a crash if( rOutlNds.empty() ) return USHRT_MAX; + SwTxtNode* pNd; nPos = 0; // search in the existing outline nodes for the required outline num array @@ -700,7 +700,7 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const // 1. step: via the Number: OUString sName( rName ); - sal_uInt16 nFndPos = ::lcl_FindOutlineNum( GetNodes(), sName ); + sal_uInt16 nFndPos = ::lcl_FindOutlineNum( rOutlNds, sName ); if( USHRT_MAX != nFndPos ) { SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); @@ -720,7 +720,7 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const if( sExpandedText != sName ) { - sal_uInt16 nTmp = ::lcl_FindOutlineName( GetNodes(), sName, true ); + sal_uInt16 nTmp = ::lcl_FindOutlineName( rOutlNds, sName, true ); if( USHRT_MAX != nTmp ) // found via the Name { nFndPos = nTmp; @@ -732,7 +732,7 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const return true; } - nFndPos = ::lcl_FindOutlineName( GetNodes(), rName, false ); + nFndPos = ::lcl_FindOutlineName( rOutlNds, rName, false ); if( USHRT_MAX != nFndPos ) { SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); @@ -744,7 +744,7 @@ bool SwDoc::GotoOutline( SwPosition& rPos, const OUString& rName ) const // #i68289# additional search on hyperlink URL without its outline numbering part if ( sName != rName ) { - nFndPos = ::lcl_FindOutlineName( GetNodes(), sName, false ); + nFndPos = ::lcl_FindOutlineName( rOutlNds, sName, false ); if( USHRT_MAX != nFndPos ) { SwTxtNode* pNd = rOutlNds[ nFndPos ]->GetTxtNode(); commit 43f04e78a33fbe25aaaef7a72f0f1bb5da007955 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 21 09:00:16 2015 +0100 Do not compare OUStrings twice Change-Id: I94f7cecf5b39c1f03b9f10a13b5efa63bb06ced8 diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index ee294d2..77dfbc5 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -570,17 +570,20 @@ static sal_uInt16 lcl_FindOutlineName( const SwNodes& rNds, const OUString& rNam for( SwOutlineNodes::size_type n = 0; n < rOutlNds.size(); ++n ) { SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); - OUString sTxt( pTxtNd->GetExpandTxt() ); - if (sTxt == rName) + const OUString sTxt( pTxtNd->GetExpandTxt() ); + if (sTxt.startsWith(rName)) { - // Found "exact", set Pos to the Node - nSavePos = n; - break; - } - else if( !bExact && USHRT_MAX == nSavePos && sTxt.startsWith(rName) ) - { - // maybe we just found the text's first part - nSavePos = n; + if (sTxt.getLength() == rName.getLength()) + { + // Found "exact", set Pos to the Node + nSavePos = n; + break; + } + else if( !bExact && USHRT_MAX == nSavePos ) + { + // maybe we just found the text's first part + nSavePos = n; + } } } commit 2b3aa996b385cab856b30b7be2f54cbcc59446eb Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 19 01:20:04 2015 +0100 Use more proper integer types and range-for loops Change-Id: Ic530e11248955133804f8d400eaef80fe33c1779 diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 1618e0b..ee294d2 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -151,10 +151,8 @@ void SwDoc::SetOutlineNumRule( const SwNumRule& rRule ) void SwDoc::PropagateOutlineRule() { - for (sal_uInt16 n = 0; n < mpTxtFmtCollTbl->size(); n++) + for (auto pColl : *mpTxtFmtCollTbl) { - SwTxtFmtColl *pColl = (*mpTxtFmtCollTbl)[n]; - if(pColl->IsAssignedToListLevelOfOutlineStyle()) { // Check only the list style, which is set at the paragraph style @@ -199,22 +197,23 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) // We now have the wanted range in the OutlineNodes array, // so check now if we're not invalidating sublevels // (stepping over the limits) - sal_uInt16 n; // Here we go: // 1. Create the style array: SwTxtFmtColl* aCollArr[ MAXLEVEL ]; memset( aCollArr, 0, sizeof( SwTxtFmtColl* ) * MAXLEVEL ); - for( n = 0; n < mpTxtFmtCollTbl->size(); ++n ) + for( auto pTxtFmtColl : *mpTxtFmtCollTbl ) { - if((*mpTxtFmtCollTbl)[ n ]->IsAssignedToListLevelOfOutlineStyle()) + if (pTxtFmtColl->IsAssignedToListLevelOfOutlineStyle()) { - const int nLevel = (*mpTxtFmtCollTbl)[ n ]->GetAssignedOutlineStyleLevel(); - aCollArr[ nLevel ] = (*mpTxtFmtCollTbl)[ n ]; + const int nLevel = pTxtFmtColl->GetAssignedOutlineStyleLevel(); + aCollArr[ nLevel ] = pTxtFmtColl; } } + int n; + /* Find the last occupied level (backward). */ for (n = MAXLEVEL - 1; n > 0; n--) { @@ -312,12 +311,12 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) */ if (aCollArr[n] != NULL) { - sal_uInt16 m = n; + int m = n; int nCount = nNum; while (nCount > 0 && m + nStep >= 0 && m + nStep < MAXLEVEL) { - m = static_cast<sal_uInt16>(m + nStep); + m += nStep; if (aCollArr[m] != NULL) nCount--; @@ -336,9 +335,9 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) outline levels occurring in the document there has to be a valid target outline level implied by aMoveArr. */ bool bMoveApplicable = true; - for (n = nSttPos; n < nEndPos; n++) + for (auto i = nSttPos; i < nEndPos; ++i) { - SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); + SwTxtNode* pTxtNd = rOutlNds[ i ]->GetTxtNode(); SwTxtFmtColl* pColl = pTxtNd->GetTxtColl(); if( pColl->IsAssignedToListLevelOfOutlineStyle() ) @@ -371,11 +370,9 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) } // 2. Apply the new style to all Nodes - - n = nSttPos; - while( n < nEndPos) + for (auto i = nSttPos; i < nEndPos; ++i) { - SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); + SwTxtNode* pTxtNd = rOutlNds[ i ]->GetTxtNode(); SwTxtFmtColl* pColl = pTxtNd->GetTxtColl(); if( pColl->IsAssignedToListLevelOfOutlineStyle() ) @@ -401,8 +398,6 @@ bool SwDoc::OutlineUpDown( const SwPaM& rPam, short nOffset ) pTxtNd->SetAttrOutlineLevel( nLevel ); } - - n++; // Undo ??? } if (GetIDocumentUndoRedo().DoesUndo()) @@ -572,7 +567,7 @@ static sal_uInt16 lcl_FindOutlineName( const SwNodes& rNds, const OUString& rNam { sal_uInt16 nSavePos = USHRT_MAX; const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds(); - for( sal_uInt16 n = 0; n < rOutlNds.size(); ++n ) + for( SwOutlineNodes::size_type n = 0; n < rOutlNds.size(); ++n ) { SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode(); OUString sTxt( pTxtNd->GetExpandTxt() ); @@ -612,7 +607,7 @@ static sal_uInt16 lcl_FindOutlineNum( const SwNodes& rNds, OUString& rName ) { sal_uInt16 nVal = 0; sal_Unicode c; - for( sal_uInt16 n = 0; n < sNum.getLength(); ++n ) + for( sal_Int32 n = 0; n < sNum.getLength(); ++n ) if( '0' <= ( c = sNum[ n ]) && c <= '9' ) { nVal *= 10; nVal += c - '0'; commit 93395b3feae258da71429b4b0b276c0f21b16e8f Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 07:26:19 2015 +0100 Use more proper/automatic integer types and range-for loops Change-Id: I188dc79dbba234b844e7c047ccc186d99c214ac7 diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index c2f56aa3..9eba48e 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -465,7 +465,7 @@ SwDoc::~SwDoc() // Old - deletion without a Flag is expensive, because we send a Modify // aTOXTypes.DeleteAndDestroy( 0, aTOXTypes.Count() ); { - for( sal_uInt16 n = mpTOXTypes->size(); n; ) + for( auto n = mpTOXTypes->size(); n; ) { (*mpTOXTypes)[ --n ]->SetInDocDTOR(); delete (*mpTOXTypes)[ n ]; @@ -634,9 +634,8 @@ void SwDoc::ClearDoc() } // if there are still FlyFrames dangling around, delete them too - sal_uInt16 n; - while ( 0 != (n = GetSpzFrmFmts()->size()) ) - getIDocumentLayoutAccess().DelLayoutFmt((*mpSpzFrmFmtTbl)[n-1]); + while ( !mpSpzFrmFmtTbl->empty() ) + getIDocumentLayoutAccess().DelLayoutFmt((*mpSpzFrmFmtTbl)[mpSpzFrmFmtTbl->size()-1]); OSL_ENSURE( !GetDocumentDrawModelManager().GetDrawModel() || !GetDocumentDrawModelManager().GetDrawModel()->GetPage(0)->GetObjCount(), "not all DrawObjects removed from the page" ); @@ -826,8 +825,7 @@ void SwDoc::ReplaceDefaults(const SwDoc& rSource) SfxItemSet aNewDefaults(GetAttrPool(), aRangeOfDefaults); - sal_uInt16 nRange = 0; - while (aRangeOfDefaults[nRange] != 0) + for (auto nRange = 0; aRangeOfDefaults[nRange] != 0; nRange += 2) { for (sal_uInt16 nWhich = aRangeOfDefaults[nRange]; nWhich <= aRangeOfDefaults[nRange + 1]; ++nWhich) @@ -837,7 +835,6 @@ void SwDoc::ReplaceDefaults(const SwDoc& rSource) if (rSourceAttr != mpAttrPool->GetDefaultItem(nWhich)) aNewDefaults.Put(rSourceAttr); } - nRange += 2; } if (aNewDefaults.Count()) @@ -1016,7 +1013,7 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu } { - sal_uInt16 iDelNodes = 0; + sal_uLong iDelNodes = 0; SwNodeIndex aDelIdx( aFixupIdx ); // we just need to set the new page description and reset numbering @@ -1098,10 +1095,9 @@ else } // finally copy page bound frames - const SwFrmFmts *pSpzFrmFmts = rSource.GetSpzFrmFmts(); - for ( sal_uInt16 i = 0; i < pSpzFrmFmts->size(); ++i ) + for ( auto pCpyFmt : *rSource.GetSpzFrmFmts() ) { - const SwFrmFmt& rCpyFmt = *(*pSpzFrmFmts)[i]; + const SwFrmFmt& rCpyFmt = *pCpyFmt; SwFmtAnchor aAnchor( rCpyFmt.GetAnchor() ); if (FLY_AT_PAGE != aAnchor.GetAnchorId()) continue; commit 36a001be93fa6ab4321a7a98bcb60c02ec93746b Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 07:17:18 2015 +0100 Reduce temporaries Change-Id: Ie819ed8835ec30b99186d34382d6cd3e63532865 diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 8cc7730..2729862 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -134,7 +134,7 @@ SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, bool bMoveWithinDoc, uno::Reference< awt::XControlModel > xModel = static_cast<SdrUnoObj*>(pObj)->GetUnoControlModel(); uno::Any aVal; uno::Reference< beans::XPropertySet > xSet(xModel, uno::UNO_QUERY); - OUString sName("Name"); + const OUString sName("Name"); if( xSet.is() ) aVal = xSet->getPropertyValue( sName ); if( bInsInPage ) @@ -1327,7 +1327,7 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) } } - return aName += OUString::number( ++nNum ); + return aName + OUString::number( ++nNum ); } OUString SwDoc::GetUniqueGrfName() const @@ -1398,9 +1398,9 @@ void SwDoc::SetAllUniqueFlyNames() ResId nFrmId( STR_FRAME_DEFNAME, *pSwResMgr ), nGrfId( STR_GRAPHIC_DEFNAME, *pSwResMgr ), nOLEId( STR_OBJECT_DEFNAME, *pSwResMgr ); - OUString sFlyNm( nFrmId ); - OUString sGrfNm( nGrfId ); - OUString sOLENm( nOLEId ); + const OUString sFlyNm( nFrmId ); + const OUString sGrfNm( nGrfId ); + const OUString sOLENm( nOLEId ); if( 255 < ( n = GetSpzFrmFmts()->size() )) n = 255; @@ -1465,24 +1465,18 @@ void SwDoc::SetAllUniqueFlyNames() if( 0 != ( pIdx = ( pFlyFmt = aArr[ --n ])->GetCntnt().GetCntntIdx() ) && pIdx->GetNode().GetNodes().IsDocNodes() ) { - sal_Int32 nNum; - OUString sNm; switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() ) { case ND_GRFNODE: - sNm = sGrfNm; - nNum = ++nGrfNum; + pFlyFmt->SetName( sGrfNm + OUString::number( ++nGrfNum )); break; case ND_OLENODE: - sNm = sOLENm; - nNum = ++nOLENum; + pFlyFmt->SetName( sOLENm + OUString::number( ++nOLENum )); break; default: - sNm = sFlyNm; - nNum = ++nFlyNum; + pFlyFmt->SetName( sFlyNm + OUString::number( ++nFlyNum )); break; } - pFlyFmt->SetName( sNm + OUString::number( nNum )); } } aArr.clear(); commit df32b977f5b222367e4015665aa1a2ede14e26a0 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 07:11:55 2015 +0100 Use more proper/automatic integer types and range-for loops Change-Id: I3ef0f9cc7c116cf7437df7645d05cc494a452ba3 diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index f40feb9..8cc7730 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -512,12 +512,10 @@ SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, bool bDrawAlso, bool bAsCharAlso ) const { SwPosFlyFrms aRetval; - SwFrmFmt *pFly; // collect all anchored somehow to paragraphs - for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n ) + for( auto pFly : *GetSpzFrmFmts() ) { - pFly = (*GetSpzFrmFmts())[ n ]; bool bDrawFmt = bDrawAlso && RES_DRAWFRMFMT == pFly->Which(); bool bFlyFmt = RES_FLYFRMFMT == pFly->Which(); if( bFlyFmt || bDrawFmt ) @@ -554,6 +552,7 @@ SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, bool bDrawAlso, for( size_t i = 0; i < rObjs.size(); ++i) { SwAnchoredObject* pAnchoredObj = rObjs[i]; + SwFrmFmt *pFly; if ( pAnchoredObj->ISA(SwFlyFrm) ) pFly = &(pAnchoredObj->GetFrmFmt()); else if ( bDrawAlso ) @@ -655,7 +654,7 @@ lcl_InsertLabel(SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl, SwTxtFmtColl * pColl = NULL; if( pType ) { - for( sal_uInt16 i = pTxtFmtCollTbl->size(); i; ) + for( auto i = pTxtFmtCollTbl->size(); i; ) { if( (*pTxtFmtCollTbl)[ --i ]->GetName()==pType->GetName() ) { @@ -1004,7 +1003,7 @@ lcl_InsertDrawLabel( SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl, SwTxtFmtColl *pColl = NULL; if( pType ) { - for( sal_uInt16 i = pTxtFmtCollTbl->size(); i; ) + for( auto i = pTxtFmtCollTbl->size(); i; ) { if( (*pTxtFmtCollTbl)[ --i ]->GetName()==pType->GetName() ) { @@ -1298,8 +1297,6 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) const SwFrmFmts& rFmts = *pDoc->GetSpzFrmFmts(); - sal_uInt16 nNum; - std::vector<sal_uInt8> aSetFlags(rFmts.size()/8 + 2); for( SwFrmFmts::size_type n = 0; n < rFmts.size(); ++n ) @@ -1309,14 +1306,14 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) pFlyFmt->GetName().startsWith( aName ) ) { // Only get and set the Flag - nNum = static_cast< sal_uInt16 >( pFlyFmt->GetName().copy( nNmLen ).toInt32() ); - if( nNum-- && nNum < rFmts.size() ) + const sal_Int32 nNum = pFlyFmt->GetName().copy( nNmLen ).toInt32()-1; + if( nNum >= 0 && static_cast<SwFrmFmts::size_type>(nNum) < rFmts.size() ) aSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 )); } } // All numbers are flagged accordingly, so determine the right one - nNum = rFmts.size(); + SwFrmFmts::size_type nNum = rFmts.size(); for( std::vector<sal_uInt8>::size_type n=0; n<aSetFlags.size(); ++n ) { sal_uInt8 nTmp = aSetFlags[ n ]; @@ -1351,7 +1348,7 @@ OUString SwDoc::GetUniqueFrameName() const const SwFlyFrmFmt* SwDoc::FindFlyByName( const OUString& rName, sal_Int8 nNdTyp ) const { const SwFrmFmts& rFmts = *GetSpzFrmFmts(); - for( sal_uInt16 n = rFmts.size(); n; ) + for( auto n = rFmts.size(); n; ) { const SwFrmFmt* pFlyFmt = rFmts[ --n ]; const SwNodeIndex* pIdx = 0; @@ -1468,7 +1465,7 @@ void SwDoc::SetAllUniqueFlyNames() if( 0 != ( pIdx = ( pFlyFmt = aArr[ --n ])->GetCntnt().GetCntntIdx() ) && pIdx->GetNode().GetNodes().IsDocNodes() ) { - sal_uInt16 nNum; + sal_Int32 nNum; OUString sNm; switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() ) { @@ -1522,10 +1519,8 @@ bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const // get up by using the Anchor #if OSL_DEBUG_LEVEL > 0 std::list<const SwFrmFmt*> checkFmts; - sal_uInt16 n; - for( n = 0; n < GetSpzFrmFmts()->size(); ++n ) + for( auto pFmt : *GetSpzFrmFmts() ) { - const SwFrmFmt* pFmt = (*GetSpzFrmFmts())[ n ]; const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx(); if( pIdx && pFlyNd == &pIdx->GetNode() ) checkFmts.push_back( pFmt ); commit bfa9da7cdf02ba78aee2390599d840075122c702 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 01:05:31 2015 +0100 Use a vector instead of manual memory allocation Change-Id: I506d48b944cc3d53347aad669119a78a47559c4d diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 10a7216..f40feb9 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -1298,13 +1298,11 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) const SwFrmFmts& rFmts = *pDoc->GetSpzFrmFmts(); - sal_uInt16 nNum, nTmp, nFlagSize = ( rFmts.size() / 8 ) +2; - sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ]; - sal_uInt16 n; + sal_uInt16 nNum; - memset( pSetFlags, 0, nFlagSize ); + std::vector<sal_uInt8> aSetFlags(rFmts.size()/8 + 2); - for( n = 0; n < rFmts.size(); ++n ) + for( SwFrmFmts::size_type n = 0; n < rFmts.size(); ++n ) { const SwFrmFmt* pFlyFmt = rFmts[ n ]; if( RES_FLYFRMFMT == pFlyFmt->Which() && @@ -1313,14 +1311,16 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) // Only get and set the Flag nNum = static_cast< sal_uInt16 >( pFlyFmt->GetName().copy( nNmLen ).toInt32() ); if( nNum-- && nNum < rFmts.size() ) - pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 )); + aSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 )); } } // All numbers are flagged accordingly, so determine the right one nNum = rFmts.size(); - for( n = 0; n < nFlagSize; ++n ) - if( 0xff != ( nTmp = pSetFlags[ n ] )) + for( std::vector<sal_uInt8>::size_type n=0; n<aSetFlags.size(); ++n ) + { + sal_uInt8 nTmp = aSetFlags[ n ]; + if( 0xff != nTmp ) { // so determine the number nNum = n * 8; @@ -1328,8 +1328,8 @@ static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId ) ++nNum, nTmp >>= 1; break; } + } - delete [] pSetFlags; return aName += OUString::number( ++nNum ); } commit 8097a5b0847ed62caaa08b4c7a15315ee9d6866d Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:58:29 2015 +0100 Use more proper types Change-Id: I548370202d81abe0348a082da0d321260aa8cd37 diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx index 017a4f5..c76c12d 100644 --- a/sw/source/core/doc/docglbl.cxx +++ b/sw/source/core/doc/docglbl.cxx @@ -186,7 +186,7 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, { // Look for the 1st level OutlineTemplate const SwTxtFmtColls& rFmtColls =*GetTxtFmtColls(); - for( sal_uInt16 n = rFmtColls.size(); n; ) + for( SwTxtFmtColls::size_type n = rFmtColls.size(); n; ) if ( rFmtColls[ --n ]->GetAttrOutlineLevel() == 1 ) { pSplitColl = rFmtColls[ n ]; @@ -372,7 +372,7 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, CorrAbs( aSIdx, aEIdx, *aTmp.GetPoint(), true); // If FlyFrames are still around, delete these too - for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n ) + for( SwFrmFmts::size_type n = 0; n < GetSpzFrmFmts()->size(); ++n ) { SwFrmFmt* pFly = (*GetSpzFrmFmts())[n]; const SwFmtAnchor* pAnchor = &pFly->GetAnchor(); commit 1b4d55645da61804c029f496a6ffb4febe99345a Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:56:26 2015 +0100 Use more proper types/range-for loops, reduce scope Change-Id: I2749ce16f870fb7af2dea23452bec0ec7f8de625 diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 131ea4e..59d08aa 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -133,7 +133,7 @@ static bool lcl_RstAttr( const SwNodePtr& rpNd, void* pArgs ) const SfxPoolItem* pItem; sal_uInt16 const aSavIds[3] = { RES_PAGEDESC, RES_BREAK, RES_PARATR_NUMRULE }; - for (sal_uInt16 n = 0; n < 3; ++n) + for (int n = 0; n < 3; ++n) { if (SfxItemState::SET == pAttrSetOfNode->GetItemState(aSavIds[n], false, &pItem)) { @@ -547,13 +547,12 @@ void SwDoc::SetDefault( const SfxItemSet& rSet ) SwAttrSet aOld( GetAttrPool(), rSet.GetRanges() ), aNew( GetAttrPool(), rSet.GetRanges() ); SfxItemIter aIter( rSet ); - sal_uInt16 nWhich; const SfxPoolItem* pItem = aIter.GetCurItem(); SfxItemPool* pSdrPool = GetAttrPool().GetSecondaryPool(); while( true ) { bool bCheckSdrDflt = false; - nWhich = pItem->Which(); + const sal_uInt16 nWhich = pItem->Which(); aOld.Put( GetAttrPool().GetDefaultItem( nWhich ) ); GetAttrPool().SetPoolDefaultItem( *pItem ); aNew.Put( GetAttrPool().GetDefaultItem( nWhich ) ); @@ -1109,7 +1108,7 @@ SwFmt* SwDoc::CopyFmt( const SwFmt& rFmt, // It's no autoformat, default format or collection format, // then search for it. if( !rFmt.IsAuto() || !rFmt.GetRegisteredIn() ) - for( sal_uInt16 n = 0; n < rFmtArr.GetFmtCount(); n++ ) + for( size_t n = 0; n < rFmtArr.GetFmtCount(); ++n ) { // Does the Doc already contain the template? if( rFmtArr.GetFmt(n)->GetName()==rFmt.GetName() ) @@ -1251,11 +1250,10 @@ void SwDoc::CopyFmtArr( const SwFmtsBase& rSourceArr, FNCopyFmt fnCopyFmt, SwFmt& rDfltFmt ) { - sal_uInt16 nSrc; SwFmt* pSrc, *pDest; // 1st step: Create all formats (skip the 0th - it's the default one) - for( nSrc = rSourceArr.GetFmtCount(); nSrc > 1; ) + for( size_t nSrc = rSourceArr.GetFmtCount(); nSrc > 1; ) { pSrc = (SwFmt*)rSourceArr.GetFmt( --nSrc ); if( pSrc->IsDefault() || pSrc->IsAuto() ) @@ -1272,7 +1270,7 @@ void SwDoc::CopyFmtArr( const SwFmtsBase& rSourceArr, } // 2nd step: Copy all attributes, set the right parents - for( nSrc = rSourceArr.GetFmtCount(); nSrc > 1; ) + for( size_t nSrc = rSourceArr.GetFmtCount(); nSrc > 1; ) { pSrc = (SwFmt*)rSourceArr.GetFmt( --nSrc ); if( pSrc->IsDefault() || pSrc->IsAuto() ) @@ -1533,8 +1531,6 @@ void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles ) CopyFmtArr( *rSource.mpTxtFmtCollTbl, *mpTxtFmtCollTbl, &SwDoc::_MakeTxtFmtColl, *mpDfltTxtFmtColl ); - sal_uInt16 nCnt; - //To-Do: // a) in rtf export don't export our hideous pgdsctbl // extension to rtf anymore @@ -1545,7 +1541,7 @@ void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles ) if (bIncludePageStyles) { // and now the page templates - nCnt = rSource.maPageDescs.size(); + SwPageDescs::size_type nCnt = rSource.maPageDescs.size(); if( nCnt ) { // a different Doc -> Number formatter needs to be merged @@ -1570,11 +1566,11 @@ void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles ) } // then there are the numbering templates - nCnt = rSource.GetNumRuleTbl().size(); + const SwPageDescs::size_type nCnt = rSource.GetNumRuleTbl().size(); if( nCnt ) { const SwNumRuleTbl& rArr = rSource.GetNumRuleTbl(); - for( sal_uInt16 n = 0; n < nCnt; ++n ) + for( SwPageDescs::size_type n = 0; n < nCnt; ++n ) { const SwNumRule& rR = *rArr[ n ]; SwNumRule* pNew = FindNumRulePtr( rR.GetName()); @@ -1609,7 +1605,7 @@ SwFmt* SwDoc::FindFmtByName( const SwFmtsBase& rFmtArr, const OUString& rName ) const { SwFmt* pFnd = 0; - for( sal_uInt16 n = 0; n < rFmtArr.GetFmtCount(); n++ ) + for( size_t n = 0; n < rFmtArr.GetFmtCount(); ++n ) { // Does the Doc already contain the template? if( rFmtArr.GetFmt(n)->GetName() == rName ) @@ -1633,8 +1629,7 @@ void SwDoc::MoveLeftMargin( const SwPaM& rPam, bool bRight, bool bModulus ) } const SvxTabStopItem& rTabItem = static_cast<const SvxTabStopItem&>(GetDefault( RES_PARATR_TABSTOP )); - sal_uInt16 nDefDist = rTabItem.Count() ? - static_cast<sal_uInt16>(rTabItem[0].GetTabPos()) : 1134; + const sal_Int32 nDefDist = rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134; const SwPosition &rStt = *rPam.Start(), &rEnd = *rPam.End(); SwNodeIndex aIdx( rStt.nNode ); while( aIdx <= rEnd.nNode ) @@ -1956,11 +1951,8 @@ namespace docfunc const SwTxtFmtColls* pTxtFmtColls( rDoc.GetTxtFmtColls() ); if ( pTxtFmtColls ) { - const sal_uInt16 nCount = pTxtFmtColls->size(); - for ( sal_uInt16 i = 0; i < nCount; ++i ) + for ( auto pTxtFmtColl : *pTxtFmtColls ) { - SwTxtFmtColl* pTxtFmtColl = (*pTxtFmtColls)[i]; - if ( pTxtFmtColl->IsDefault() || ! pTxtFmtColl->IsAssignedToListLevelOfOutlineStyle() ) { commit f473167aaaa85f74a1da247340d7bd18a2128933 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:46:46 2015 +0100 Use range-for loop Change-Id: I1a4c031cb1d65dbdb4f9290997eb65e7738df1d3 diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx index 6c26ce4..0e39cfb 100644 --- a/sw/source/core/doc/docfly.cxx +++ b/sw/source/core/doc/docfly.cxx @@ -970,10 +970,9 @@ int SwDoc::Chainable( const SwFrmFmt &rSource, const SwFrmFmt &rDest ) return SW_CHAIN_NOT_EMPTY; } - sal_uInt16 nArrLen = GetSpzFrmFmts()->size(); - for( sal_uInt16 n = 0; n < nArrLen; ++n ) + for( auto pSpzFrmFm : *GetSpzFrmFmts() ) { - const SwFmtAnchor& rAnchor = (*GetSpzFrmFmts())[ n ]->GetAnchor(); + const SwFmtAnchor& rAnchor = pSpzFrmFm->GetAnchor(); sal_uLong nTstSttNd; // #i20622# - to-frame anchored objects are allowed. if ( ((rAnchor.GetAnchorId() == FLY_AT_PARA) || commit bdfe8a2680b27f2f887729f80d8c0cbb831a0674 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:44:12 2015 +0100 Avoid unnecessary OUString copies Change-Id: Idd61ad459103f35e7a5094c112eb3294fedb7f90 diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 44ad6e2..69e4966 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -415,12 +415,9 @@ void SwDoc::SetInitDBFields( bool b ) /// Get all databases that are used by fields static OUString lcl_DBDataToString(const SwDBData& rData) { - OUString sRet = rData.sDataSource; - sRet += OUString(DB_DELIM); - sRet += rData.sCommand; - sRet += OUString(DB_DELIM); - sRet += OUString::number(rData.nCommandType); - return sRet; + return rData.sDataSource + OUString(DB_DELIM) + + rData.sCommand + OUString(DB_DELIM) + + OUString::number(rData.nCommandType); } #endif @@ -448,9 +445,8 @@ void SwDoc::GetAllUsedDB( std::vector<OUString>& rDBNameList, if( pSect ) { - OUString aCond( pSect->GetCondition() ); AddUsedDBToList( rDBNameList, FindUsedDBs( *pAllDBNames, - aCond, aUsedDBNames ) ); + pSect->GetCondition(), aUsedDBNames ) ); aUsedDBNames.clear(); } } @@ -526,28 +522,25 @@ std::vector<OUString>& SwDoc::FindUsedDBs( const std::vector<OUString>& rAllDBNa std::vector<OUString>& rUsedDBNames ) { const CharClass& rCC = GetAppCharClass(); - OUString sFormula(rFormula); #ifndef UNX - sFormula = rCC.uppercase( sFormula ); + const OUString sFormula(rCC.uppercase( rFormula )); +#else + const OUString sFormula(rFormula); #endif for (const auto &sItem : rAllDBNames) { - OUString pStr(sItem); - - sal_Int32 nPos = sFormula.indexOf( pStr ); + sal_Int32 nPos = sFormula.indexOf( sItem ); if( nPos>=0 && - sFormula[ nPos + pStr.getLength() ] == '.' && + sFormula[ nPos + sItem.getLength() ] == '.' && (!nPos || !rCC.isLetterNumeric( sFormula, nPos - 1 ))) { // Look up table name - nPos += pStr.getLength() + 1; + nPos += sItem.getLength() + 1; const sal_Int32 nEndPos = sFormula.indexOf('.', nPos); if( nEndPos>=0 ) { - pStr += OUString( DB_DELIM ); - pStr += sFormula.copy( nPos, nEndPos - nPos ); - rUsedDBNames.push_back(pStr); + rUsedDBNames.push_back(sItem + OUString( DB_DELIM ) + sFormula.copy( nPos, nEndPos - nPos )); } } } commit e6ebf3428345c975a2188177dc812c00fee5cc06 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:39:04 2015 +0100 Reduce scope of some variables Change-Id: Id7a6280bed69059980d5b8f46c80e9dc4a290bba diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 7a5807c..44ad6e2 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -531,19 +531,19 @@ std::vector<OUString>& SwDoc::FindUsedDBs( const std::vector<OUString>& rAllDBNa sFormula = rCC.uppercase( sFormula ); #endif - sal_Int32 nPos; for (const auto &sItem : rAllDBNames) { OUString pStr(sItem); - if( -1 != (nPos = sFormula.indexOf( pStr )) && + sal_Int32 nPos = sFormula.indexOf( pStr ); + if( nPos>=0 && sFormula[ nPos + pStr.getLength() ] == '.' && (!nPos || !rCC.isLetterNumeric( sFormula, nPos - 1 ))) { // Look up table name - sal_Int32 nEndPos; nPos += pStr.getLength() + 1; - if( -1 != (nEndPos = sFormula.indexOf('.', nPos)) ) + const sal_Int32 nEndPos = sFormula.indexOf('.', nPos); + if( nEndPos>=0 ) { pStr += OUString( DB_DELIM ); pStr += sFormula.copy( nPos, nEndPos - nPos ); @@ -613,12 +613,12 @@ void SwDoc::ChangeDBFields( const std::vector<OUString>& rOldNames, } } - const SfxPoolItem* pItem; sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_FIELD ); for (sal_uInt32 n = 0; n < nMaxItems; ++n ) { - if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_FIELD, n ) )) + const SfxPoolItem* pItem = GetAttrPool().GetItem2( RES_TXTATR_FIELD, n ); + if( !pItem ) continue; SwFmtFld* pFmtFld = const_cast<SwFmtFld*>(static_cast<const SwFmtFld*>(pItem)); @@ -891,12 +891,12 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) #if HAVE_FEATURE_DBCONNECTIVITY bool bIsDBManager = 0 != rDoc.GetDBManager(); #endif - sal_uInt16 nWhich; - const SfxPoolItem* pItem; + const sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_TXTATR_FIELD ); for( sal_uInt32 n = 0; n < nMaxItems; ++n ) { - if( 0 == (pItem = rDoc.GetAttrPool().GetItem2( RES_TXTATR_FIELD, n )) ) + const SfxPoolItem* pItem = rDoc.GetAttrPool().GetItem2( RES_TXTATR_FIELD, n ); + if( !pItem ) continue; const SwFmtFld* pFmtFld = static_cast<const SwFmtFld*>(pItem); @@ -906,7 +906,8 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) OUString sFormula; const SwField* pFld = pFmtFld->GetField(); - switch( nWhich = pFld->GetTyp()->Which() ) + const sal_uInt16 nWhich = pFld->GetTyp()->Which(); + switch( nWhich ) { case RES_DBSETNUMBERFLD: case RES_GETEXPFLD: commit 61b0498b0f8aca326469d4a9be481f4bc0bd47c5 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Thu Feb 12 00:28:02 2015 +0100 Use more proper integer types and range-for loops Change-Id: I2c3dbad8037a1d7d2d3e0fdb161d1c652f49ec47 diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 439c421..7a5807c 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -363,8 +363,8 @@ const SwDBData& SwDoc::GetDBDesc() #if HAVE_FEATURE_DBCONNECTIVITY if(maDBData.sDataSource.isEmpty()) { - const sal_uInt16 nSize = getIDocumentFieldsAccess().GetFldTypes()->size(); - for(sal_uInt16 i = 0; i < nSize && maDBData.sDataSource.isEmpty(); ++i) + const SwFldTypes::size_type nSize = getIDocumentFieldsAccess().GetFldTypes()->size(); + for(SwFldTypes::size_type i = 0; i < nSize && maDBData.sDataSource.isEmpty(); ++i) { SwFieldType& rFldType = *((*getIDocumentFieldsAccess().GetFldTypes())[i]); sal_uInt16 nWhich = rFldType.Which(); @@ -442,7 +442,7 @@ void SwDoc::GetAllUsedDB( std::vector<OUString>& rDBNameList, } SwSectionFmts& rArr = GetSections(); - for (sal_uInt16 n = rArr.size(); n; ) + for (auto n = rArr.size(); n; ) { SwSection* pSect = rArr[ --n ]->GetSection(); @@ -514,10 +514,9 @@ void SwDoc::GetAllDBNames( std::vector<OUString>& rAllDBNames ) SwDBManager* pMgr = GetDBManager(); const SwDSParamArr& rArr = pMgr->GetDSParamArray(); - for(sal_uInt16 i = 0; i < rArr.size(); i++) + for(const auto &aParam : rArr) { - const SwDSParam* pParam = &rArr[i]; - rAllDBNames.push_back(pParam->sDataSource + OUString(DB_DELIM) + pParam->sCommand); + rAllDBNames.push_back(aParam.sDataSource + OUString(DB_DELIM) + aParam.sCommand); } #endif } @@ -533,9 +532,9 @@ std::vector<OUString>& SwDoc::FindUsedDBs( const std::vector<OUString>& rAllDBNa #endif sal_Int32 nPos; - for (sal_uInt16 i = 0; i < rAllDBNames.size(); ++i ) + for (const auto &sItem : rAllDBNames) { - OUString pStr(rAllDBNames[i]); + OUString pStr(sItem); if( -1 != (nPos = sFormula.indexOf( pStr )) && sFormula[ nPos + pStr.getLength() ] == '.' && @@ -558,8 +557,8 @@ std::vector<OUString>& SwDoc::FindUsedDBs( const std::vector<OUString>& rAllDBNa void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList, const std::vector<OUString>& rUsedDBNames ) { - for (sal_uInt16 i = 0; i < rUsedDBNames.size(); ++i) - AddUsedDBToList( rDBNameList, rUsedDBNames[i] ); + for ( const auto &sName : rUsedDBNames ) + AddUsedDBToList( rDBNameList, sName ); } void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList, const OUString& rDBName) @@ -572,13 +571,13 @@ void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList, const OUString& return; #ifdef UNX - for( sal_uInt16 i = 0; i < rDBNameList.size(); ++i ) - if( rDBName == rDBNameList[i].getToken(0, ';') ) + for( const auto &sName : rDBNameList ) + if( rDBName == sName.getToken(0, ';') ) return; #else const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); - for( sal_uInt16 i = 0; i < rDBNameList.size(); ++i ) - if( rSCmp.isEqual( rDBName, rDBNameList[i].getToken(0, ';') ) ) + for( const auto &sName : rDBNameList ) + if( rSCmp.isEqual( rDBName, sName.getToken(0, ';') ) ) return; #endif @@ -604,7 +603,7 @@ void SwDoc::ChangeDBFields( const std::vector<OUString>& rOldNames, aNewDBData.nCommandType = (short)rNewName.getToken(2, DB_DELIM).toInt32(); SwSectionFmts& rArr = GetSections(); - for (sal_uInt16 n = rArr.size(); n; ) + for (auto n = rArr.size(); n; ) { SwSection* pSect = rArr[ --n ]->GetSection(); @@ -741,13 +740,13 @@ OUString SwDoc::ReplaceUsedDBs( const std::vector<OUString>& rUsedDBNames, bool SwDoc::IsNameInArray( const std::vector<OUString>& rArr, const OUString& rName ) { #ifdef UNX - for( sal_uInt16 i = 0; i < rArr.size(); ++i ) - if( rName == rArr[ i ] ) + for( const auto &sName : rArr ) + if( rName == sName ) return true; #else const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); - for( sal_uInt16 i = 0; i < rArr.size(); ++i ) - if( rSCmp.isEqual( rName, rArr[ i] )) + for( const auto &sName : rArr ) + if( rSCmp.isEqual( rName, sName )) return true; #endif return false; @@ -755,9 +754,9 @@ bool SwDoc::IsNameInArray( const std::vector<OUString>& rArr, const OUString& rN void SwDoc::ChangeAuthorityData( const SwAuthEntry* pNewData ) { - const sal_uInt16 nSize = getIDocumentFieldsAccess().GetFldTypes()->size(); + const SwFldTypes::size_type nSize = getIDocumentFieldsAccess().GetFldTypes()->size(); - for( sal_uInt16 i = INIT_FLDTYPES; i < nSize; ++i ) + for( SwFldTypes::size_type i = INIT_FLDTYPES; i < nSize; ++i ) { SwFieldType* pFldType = (*getIDocumentFieldsAccess().GetFldTypes())[i]; if( RES_AUTHORITY == pFldType->Which() ) @@ -803,7 +802,7 @@ void SwDocUpdtFld::InsDelFldInFldLst( bool bIns, const SwTxtFld& rFld ) { // look up via the pTxtFld pointer. It is a sorted list, but it's sorted by node // position. Until this is found, the search for the pointer is already done. - for( sal_uInt16 n = 0; n < pFldSortLst->size(); ++n ) + for( _SetGetExpFlds::size_type n = 0; n < pFldSortLst->size(); ++n ) if( &rFld == (*pFldSortLst)[ n ]->GetPointer() ) { delete (*pFldSortLst)[n]; @@ -845,12 +844,12 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) // In order for the frames to be created the right way, they have to be expanded // from top to bottom std::vector<sal_uLong> aTmpArr; + std::vector<sal_uLong>::size_type nArrStt = 0; SwSectionFmts& rArr = rDoc.GetSections(); SwSectionNode* pSectNd = 0; - sal_uInt16 nArrStt = 0; sal_uLong nSttCntnt = rDoc.GetNodes().GetEndOfExtras().GetIndex(); - for (sal_uInt16 n = rArr.size(); n; ) + for (SwSectionFmts::size_type n = rArr.size(); n; ) { SwSection* pSect = rArr[ --n ]->GetSection(); if( pSect && pSect->IsHidden() && !pSect->GetCondition().isEmpty() && @@ -866,13 +865,13 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) // Display all first so that we have frames. The BodyAnchor is defined by that. // First the ContentArea, then the special areas! - for (sal_uInt16 n = nArrStt; n < aTmpArr.size(); ++n) + for (std::vector<sal_uLong>::size_type n = nArrStt; n < aTmpArr.size(); ++n) { pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode(); OSL_ENSURE( pSectNd, "Where is my SectionNode" ); pSectNd->GetSection().SetCondHidden( false ); } - for (sal_uInt16 n = 0; n < nArrStt; ++n) + for (std::vector<sal_uLong>::size_type n = 0; n < nArrStt; ++n) { pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode(); OSL_ENSURE( pSectNd, "Where is my SectionNode" ); @@ -880,9 +879,9 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) } // add all to the list so that they are sorted - for (sal_uInt16 n = 0; n < aTmpArr.size(); ++n) + for (const auto &nId : aTmpArr) { - GetBodyNode( *rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode() ); + GetBodyNode( *rDoc.GetNodes()[ nId ]->GetSectionNode() ); } } @@ -892,10 +891,10 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode ) #if HAVE_FEATURE_DBCONNECTIVITY bool bIsDBManager = 0 != rDoc.GetDBManager(); #endif - sal_uInt16 nWhich, n; + sal_uInt16 nWhich; const SfxPoolItem* pItem; - sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_TXTATR_FIELD ); - for( n = 0; n < nMaxItems; ++n ) + const sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_TXTATR_FIELD ); + for( sal_uInt32 n = 0; n < nMaxItems; ++n ) { if( 0 == (pItem = rDoc.GetAttrPool().GetItem2( RES_TXTATR_FIELD, n )) ) continue; @@ -1182,7 +1181,7 @@ SwDocUpdtFld::~SwDocUpdtFld() { delete pFldSortLst; - for( sal_uInt16 n = 0; n < TBLSZ; ++n ) + for( int n = 0; n < TBLSZ; ++n ) delete aFldTypeTable[n]; } commit b56b36718c630b0723b6df3126e2137d4cf3735e Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 7 19:05:51 2015 +0100 Use more proper integer types Change-Id: Ibba87aacffc78a80c48c6af0d5cb3e52f49b756c diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index 4d54166..55100ff 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -86,7 +86,7 @@ void _RestFlyInRange( _SaveFlyArr & rArr, const SwNodeIndex& rSttIdx, void _SaveFlyInRange( const SwNodeRange& rRg, _SaveFlyArr& rArr ) { SwFrmFmts& rFmts = *rRg.aStart.GetNode().GetDoc()->GetSpzFrmFmts(); - for( sal_uInt16 n = 0; n < rFmts.size(); ++n ) + for( SwFrmFmts::size_type n = 0; n < rFmts.size(); ++n ) { SwFrmFmt *const pFmt = rFmts[n]; SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor(); @@ -125,7 +125,7 @@ void _SaveFlyInRange( const SwPaM& rPam, const SwNodeIndex& rInsPos, const SwNodeIndex* pCntntIdx; - for( sal_uInt16 n = 0; n < rFmts.size(); ++n ) + for( SwFrmFmts::size_type n = 0; n < rFmts.size(); ++n ) { pFmt = (SwFrmFmt*)rFmts[n]; pAnchor = &pFmt->GetAnchor(); @@ -177,7 +177,7 @@ void DelFlyInRange( const SwNodeIndex& rMkNdIdx, SwDoc* pDoc = rMkNdIdx.GetNode().GetDoc(); SwFrmFmts& rTbl = *pDoc->GetSpzFrmFmts(); - for ( sal_uInt16 i = rTbl.size(); i; ) + for ( auto i = rTbl.size(); i; ) { SwFrmFmt *pFmt = rTbl[--i]; const SwFmtAnchor &rAnch = pFmt->GetAnchor(); @@ -268,7 +268,7 @@ void _SaveRedlEndPosForRestore::_Restore() if( pNode ) { SwPosition aPos( *pSavIdx, SwIndex( pNode, nSavCntnt )); - for( sal_uInt16 n = pSavArr->size(); n; ) + for( auto n = pSavArr->size(); n; ) *(*pSavArr)[ --n ] = aPos; } } @@ -457,10 +457,10 @@ static void lcl_syncGrammarError( SwTxtNode &rTxtNode, linguistic2::Proofreading return; SwGrammarMarkUp* pWrong = rTxtNode.GetGrammarCheck(); linguistic2::SingleProofreadingError* pArray = rResult.aErrors.getArray(); - sal_uInt16 i, j = 0; + sal_uInt16 j = 0; if( pWrong ) { - for( i = 0; i < rResult.aErrors.getLength(); ++i ) + for( sal_Int32 i = 0; i < rResult.aErrors.getLength(); ++i ) { const linguistic2::SingleProofreadingError &rError = rResult.aErrors[i]; const sal_Int32 nStart = rConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos; commit 9c5bfff952237e45a5dcc653cb7477c454b531f3 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 7 18:53:29 2015 +0100 Use size_type Change-Id: I4b4e88d87d96b39186afab1082e5945f441260fe diff --git a/sw/source/core/doc/doccorr.cxx b/sw/source/core/doc/doccorr.cxx index 7cf4630..76aae57 100644 --- a/sw/source/core/doc/doccorr.cxx +++ b/sw/source/core/doc/doccorr.cxx @@ -180,7 +180,7 @@ void SwDoc::CorrAbs(const SwNodeIndex& rOldNode, // fix redlines { SwRedlineTbl& rTbl = getIDocumentRedlineAccess().GetRedlineTbl(); - for (sal_uInt16 n = 0; n < rTbl.size(); ) + for (SwRedlineTbl::size_type n = 0; n < rTbl.size(); ) { // is on position ?? SwRangeRedline *const pRedline( rTbl[ n ] ); @@ -306,7 +306,7 @@ void SwDoc::CorrRel(const SwNodeIndex& rOldNode, { // fix the Redlines SwRedlineTbl& rTbl = getIDocumentRedlineAccess().GetRedlineTbl(); SwPosition aNewPos(rNewPos); - for( sal_uInt16 n = 0; n < rTbl.size(); ++n ) + for( SwRedlineTbl::size_type n = 0; n < rTbl.size(); ++n ) { // lies on the position ?? lcl_PaMCorrRel1( rTbl[ n ], &rOldNode.GetNode(), aNewPos, aNewPos.nContent.GetIndex() + nOffset ); diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index cce0277..c489c62 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -415,7 +415,7 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged ) // If the numbering scheme has changed we could have QuoVadis/ErgoSum texts // that refer to a changed page, so we invalidate foot notes. SwFtnIdxs& rFtnIdxs = GetFtnIdxs(); - for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.size(); ++nPos ) + for( SwFtnIdxs::size_type nPos = 0; nPos < rFtnIdxs.size(); ++nPos ) { SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ]; const SwFmtFtn &rFtn = pTxtFtn->GetFtn(); @@ -582,7 +582,7 @@ void SwDoc::PreDelPageDesc(SwPageDesc * pDel) } } - for ( sal_uInt16 j = 0; j < maPageDescs.size(); ++j ) + for ( SwPageDescs::size_type j = 0; j < maPageDescs.size(); ++j ) { if ( maPageDescs[j].GetFollow() == pDel ) { @@ -689,7 +689,7 @@ SwPageDesc* SwDoc::FindPageDesc(const OUString& rName, sal_uInt16* pPos) SwPageDesc* pRet = NULL; if( pPos ) *pPos = USHRT_MAX; - for( sal_uInt16 n = 0, nEnd = maPageDescs.size(); n < nEnd; ++n ) + for( SwPageDescs::size_type n = 0, nEnd = maPageDescs.size(); n < nEnd; ++n ) { if( maPageDescs[ n ].HasName( rName ) ) { @@ -750,7 +750,7 @@ void SwDoc::PrtOLENotify( bool bAll ) 0, pNodes->size(), GetDocShell()); getIDocumentLayoutAccess().GetCurrentLayout()->StartAllAction(); - for( sal_uInt16 i = 0; i < pNodes->size(); ++i ) + for( SwOLENodes::size_type i = 0; i < pNodes->size(); ++i ) { ::SetProgressState( i, GetDocShell() ); @@ -770,7 +770,7 @@ void SwDoc::PrtOLENotify( bool bAll ) } bool bFound = false; - for ( sal_uInt16 j = 0; + for ( std::vector<SvGlobalName*>::size_type j = 0; j < pGlobalOLEExcludeList->size() && !bFound; ++j ) { @@ -808,7 +808,7 @@ IMPL_LINK( SwDoc, DoUpdateModifiedOLE, Timer *, ) getIDocumentLayoutAccess().GetCurrentLayout()->StartAllAction(); SwMsgPoolItem aMsgHint( RES_UPDATE_ATTR ); - for( sal_uInt16 i = 0; i < pNodes->size(); ++i ) + for( SwOLENodes::size_type i = 0; i < pNodes->size(); ++i ) { ::SetProgressState( i, GetDocShell() ); commit b56614c6bc8d32a68099c7841ba4a4076f584057 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 7 11:14:29 2015 +0100 Simplify loops and reduce scope of some variables Change-Id: I55f0044606a75e79d51dd40976f1492ec797b531 diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 0de789d..8d9cf08 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1286,20 +1286,20 @@ void SwRangeRedline::DelCopyOfSection(size_t nMyPos) const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl(); sal_uInt16 n = nMyPos; OSL_ENSURE( n != USHRT_MAX, "How strange. We don't exist!" ); - for( bool bBreak = false; !bBreak && n > 0; ) + while ( n > 0 ) { --n; - bBreak = true; if( rTbl[ n ]->GetBound(true) == *aPam.GetPoint() ) { rTbl[ n ]->GetBound(true) = *pEnd; - bBreak = false; + continue; } if( rTbl[ n ]->GetBound(false) == *aPam.GetPoint() ) { rTbl[ n ]->GetBound(false) = *pEnd; - bBreak = false; + continue; } + break; } SwPosition aEnd( *pEnd ); @@ -1333,41 +1333,39 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl(); std::vector<SwPosition*> aBeforeArr, aBehindArr; OSL_ENSURE( this, "this is not in the array?" ); - bool bBreak = false; - SwRedlineTbl::size_type n; - for( n = nMyPos+1; !bBreak && n < rTbl.size(); ++n ) + for( SwRedlineTbl::size_type n = nMyPos+1; n < rTbl.size(); ++n ) { - bBreak = true; if( rTbl[ n ]->GetBound(true) == *GetPoint() ) { SwRangeRedline* pRedl = rTbl[n]; aBehindArr.push_back(&pRedl->GetBound(true)); - bBreak = false; + continue; } if( rTbl[ n ]->GetBound(false) == *GetPoint() ) { SwRangeRedline* pRedl = rTbl[n]; aBehindArr.push_back(&pRedl->GetBound(false)); - bBreak = false; + continue; } + break; } - for( bBreak = false, n = nMyPos; !bBreak && n ; ) + for( SwRedlineTbl::size_type n = nMyPos; n ; ) { --n; - bBreak = true; if( rTbl[ n ]->GetBound(true) == *GetPoint() ) { SwRangeRedline* pRedl = rTbl[n]; aBeforeArr.push_back(&pRedl->GetBound(true)); - bBreak = false; + continue; } if( rTbl[ n ]->GetBound(false) == *GetPoint() ) { SwRangeRedline* pRedl = rTbl[n]; aBeforeArr.push_back(&pRedl->GetBound(false)); - bBreak = false; + continue; } + break; } const SwNode* pKeptCntntSectNode( &pCntntSect->GetNode() ); // #i95711# @@ -1436,10 +1434,10 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) // adjustment of redline table positions must take start and // end into account, not point and mark. - for( n = 0; n < aBeforeArr.size(); ++n ) - *aBeforeArr[ n ] = *Start(); - for( n = 0; n < aBehindArr.size(); ++n ) - *aBehindArr[ n ] = *End(); + for( auto& pItem : aBeforeArr ) + *pItem = *Start(); + for( auto& pItem : aBehindArr ) + *pItem = *End(); } else InvalidateRange(); commit 2aab43b2a58aa670b8d38dae1a94cd1c6ba5693c Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Sat Feb 7 11:03:45 2015 +0100 Use size_type instead of sal_uInt16 Change-Id: I7d6762f2bf7aec15255288d356ad59d161b03dfd diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 7e8c9e5..0de789d 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -52,13 +52,13 @@ using namespace com::sun::star; void sw_DebugRedline( const SwDoc* pDoc ) { - static sal_uInt16 nWatch = 0; + static SwRedlineTbl::size_type nWatch = 0; const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl(); - for( sal_uInt16 n = 0; n < rTbl.size(); ++n ) + for( SwRedlineTbl::size_type n = 0; n < rTbl.size(); ++n ) { - sal_uInt16 nDummy = 0; + SwRedlineTbl::size_type nDummy = 0; const SwRangeRedline* pCurrent = rTbl[ n ]; - const SwRangeRedline* pNext = n+1 < (sal_uInt16)rTbl.size() ? rTbl[ n+1 ] : 0; + const SwRangeRedline* pNext = n+1 < rTbl.size() ? rTbl[ n+1 ] : 0; if( pCurrent == pNext ) ++nDummy; if( n == nWatch ) @@ -1104,7 +1104,7 @@ void SwRangeRedline::MoveToSection() // In order to not move other Redlines' indices, we set them // to the end (is exclusive) const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl(); - for( sal_uInt16 n = 0; n < rTbl.size(); ++n ) + for( SwRedlineTbl::size_type n = 0; n < rTbl.size(); ++n ) { SwRangeRedline* pRedl = rTbl[ n ]; if( pRedl->GetBound(true) == *pStt ) @@ -1254,7 +1254,7 @@ void SwRangeRedline::DelCopyOfSection(size_t nMyPos) // In order to not move other Redlines' indices, we set them // to the end (is exclusive) const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl(); - for( sal_uInt16 n = 0; n < rTbl.size(); ++n ) + for( SwRedlineTbl::size_type n = 0; n < rTbl.size(); ++n ) { SwRangeRedline* pRedl = rTbl[ n ]; if( pRedl->GetBound(true) == *pStt ) @@ -1334,7 +1334,7 @@ void SwRangeRedline::MoveFromSection(size_t nMyPos) std::vector<SwPosition*> aBeforeArr, aBehindArr; OSL_ENSURE( this, "this is not in the array?" ); bool bBreak = false; - sal_uInt16 n; + SwRedlineTbl::size_type n; for( n = nMyPos+1; !bBreak && n < rTbl.size(); ++n ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits