[Libreoffice-commits] core.git: 2 commits - sc/source sw/source

Matteo Casalin matteo.casalin at yahoo.com
Wed Nov 1 10:10:38 UTC 2017


 sc/source/ui/docshell/docsh5.cxx    |   20 ++++++--------------
 sw/source/core/txtnode/fmtatr2.cxx  |   13 ++++---------
 sw/source/core/txtnode/fntcache.cxx |   10 +++-------
 sw/source/core/txtnode/fntcap.cxx   |   10 +++-------
 sw/source/core/txtnode/swfont.cxx   |   15 +++++++--------
 5 files changed, 23 insertions(+), 45 deletions(-)

New commits:
commit 7ca48ce45d8c941587e296f34cba98509e35a5b5
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Wed Nov 1 11:06:28 2017 +0100

    OUString: avoid temporaries, constify
    
    Change-Id: I595b90b16c2c2a60a61811878ad06ae729a8943c

diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx
index e0a46bff1e22..86e0053b6b31 100644
--- a/sw/source/core/txtnode/fmtatr2.cxx
+++ b/sw/source/core/txtnode/fmtatr2.cxx
@@ -138,8 +138,7 @@ SfxPoolItem* SwFormatAutoFormat::Clone( SfxItemPool* ) const
 
 bool SwFormatAutoFormat::QueryValue( uno::Any& rVal, sal_uInt8 ) const
 {
-    OUString sCharFormatName = StylePool::nameOf( mpHandle );
-    rVal <<= sCharFormatName;
+    rVal <<= StylePool::nameOf( mpHandle );
     return true;
 }
 
@@ -479,13 +478,9 @@ bool SwFormatRuby::PutValue( const uno::Any& rVal,
     switch( nMemberId )
     {
         case MID_RUBY_TEXT:
-        {
-            OUString sTmp;
-            bRet = rVal >>= sTmp;
-            m_sRubyText = sTmp;
-        }
-        break;
-         case MID_RUBY_ADJUST:
+            bRet = rVal >>= m_sRubyText;
+            break;
+        case MID_RUBY_ADJUST:
         {
             sal_Int16 nSet = 0;
             rVal >>= nSet;
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 4bba114b9522..6bca3c4c8a52 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -81,9 +81,7 @@ long EvalGridWidthAdd( const SwTextGridItem *const pGrid, const SwDrawTextInfo &
     SwDocShell* pDocShell = rInf.GetShell()->GetDoc()->GetDocShell();
     SfxStyleSheetBasePool* pBasePool = pDocShell->GetStyleSheetPool();
 
-    OUString sString(SwResId(STR_POOLCOLL_STANDARD));
-
-    SfxStyleSheetBase* pStyle = pBasePool->Find(sString, SfxStyleFamily::Para);
+    SfxStyleSheetBase* pStyle = pBasePool->Find(SwResId(STR_POOLCOLL_STANDARD), SfxStyleFamily::Para);
     SfxItemSet& aTmpSet = pStyle->GetItemSet();
     const SvxFontHeightItem &aDefaultFontItem = static_cast<const SvxFontHeightItem&>(aTmpSet.Get(RES_CHRATR_CJK_FONTSIZE));
 
@@ -625,10 +623,8 @@ static sal_uInt8 lcl_WhichPunctuation( sal_Unicode cChar )
 
 static bool lcl_IsMonoSpaceFont( const vcl::RenderContext& rOut )
 {
-    const OUString aStr1( u'\x3008' );
-    const OUString aStr2( u'\x307C' );
-    const long nWidth1 = rOut.GetTextWidth( aStr1 );
-    const long nWidth2 = rOut.GetTextWidth( aStr2 );
+    const long nWidth1 = rOut.GetTextWidth( OUString( u'\x3008' ) );
+    const long nWidth2 = rOut.GetTextWidth( OUString( u'\x307C' ) );
     return nWidth1 == nWidth2;
 }
 
diff --git a/sw/source/core/txtnode/fntcap.cxx b/sw/source/core/txtnode/fntcap.cxx
index 2965b496e2d2..ebf7a3086f02 100644
--- a/sw/source/core/txtnode/fntcap.cxx
+++ b/sw/source/core/txtnode/fntcap.cxx
@@ -478,7 +478,6 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
 
     // Look if the length of the original text and the ToUpper-converted
     // text is different. If yes, do special handling.
-    OUString aNewText;
     SwCapitalInfo aCapInf(oldText);
     bool bCaseMapLengthDiffers(aText.getLength() != oldText.getLength());
     if ( bCaseMapLengthDiffers )
@@ -576,8 +575,7 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
                 // Build an own 'changed' string for the given part of the
                 // source string and use it. That new string may differ in length
                 // from the source string.
-                const OUString aSnippet(oldText.copy(nOldPos, nPos - nOldPos));
-                aNewText = CalcCaseMap( aSnippet );
+                const OUString aNewText = CalcCaseMap( oldText.copy(nOldPos, nPos-nOldPos) );
                 aCapInf.nIdx = nOldPos;
                 aCapInf.nLen = nPos - nOldPos;
                 rDo.GetInf().SetIdx( 0 );
@@ -643,8 +641,7 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
                             // Build an own 'changed' string for the given part of the
                             // source string and use it. That new string may differ in length
                             // from the source string.
-                            const OUString aSnippet(oldText.copy(nOldPos, nTmp - nOldPos));
-                            aNewText = CalcCaseMap( aSnippet );
+                            const OUString aNewText = CalcCaseMap( oldText.copy(nOldPos, nTmp-nOldPos) );
                             aCapInf.nIdx = nOldPos;
                             aCapInf.nLen = nTmp - nOldPos;
                             rDo.GetInf().SetIdx( 0 );
@@ -684,8 +681,7 @@ void SwSubFont::DoOnCapitals( SwDoCapitals &rDo )
                         // Build an own 'changed' string for the given part of the
                         // source string and use it. That new string may differ in length
                         // from the source string.
-                        const OUString aSnippet(oldText.copy(nOldPos, nTmp - nOldPos));
-                        aNewText = CalcCaseMap( aSnippet );
+                        const OUString aNewText = CalcCaseMap( oldText.copy(nOldPos, nTmp-nOldPos) );
                         aCapInf.nIdx = nOldPos;
                         aCapInf.nLen = nTmp - nOldPos;
                         rDo.GetInf().SetIdx( 0 );
diff --git a/sw/source/core/txtnode/swfont.cxx b/sw/source/core/txtnode/swfont.cxx
index b2ac4e733251..ff67f60b34a7 100644
--- a/sw/source/core/txtnode/swfont.cxx
+++ b/sw/source/core/txtnode/swfont.cxx
@@ -1067,7 +1067,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf )
             aTextSize = pLastFont->GetTextSize( rInf );
         else
         {
-            OUString aTmp = CalcCaseMap( rInf.GetText() );
+            const OUString aTmp = CalcCaseMap( rInf.GetText() );
             const OUString oldStr = rInf.GetText();
             bool bCaseMapLengthDiffers(aTmp.getLength() != oldStr.getLength());
 
@@ -1079,7 +1079,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf )
                 sal_Int32 nOldIdx(rInf.GetIdx());
                 sal_Int32 nOldLen(rInf.GetLen());
                 const OUString aSnippet(oldStr.copy(nOldIdx, nOldLen));
-                OUString aNewText(CalcCaseMap(aSnippet));
+                const OUString aNewText(CalcCaseMap(aSnippet));
 
                 rInf.SetText( aNewText );
                 rInf.SetIdx( 0 );
@@ -1115,7 +1115,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf )
     {
         sal_Int32 nOldIdx(rInf.GetIdx());
         sal_Int32 nOldLen(rInf.GetLen());
-        OUString aNewText(CH_TXT_ATR_SUBST_FIELDSTART);
+        const OUString aNewText(CH_TXT_ATR_SUBST_FIELDSTART);
         rInf.SetText( aNewText );
         rInf.SetIdx( 0 );
         rInf.SetLen( aNewText.getLength() );
@@ -1127,7 +1127,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf )
     {
         sal_Int32 nOldIdx(rInf.GetIdx());
         sal_Int32 nOldLen(rInf.GetLen());
-        OUString aNewText(CH_TXT_ATR_SUBST_FIELDEND);
+        const OUString aNewText(CH_TXT_ATR_SUBST_FIELDEND);
         rInf.SetText( aNewText );
         rInf.SetIdx( 0 );
         rInf.SetLen( aNewText.getLength() );
@@ -1182,7 +1182,7 @@ void SwSubFont::DrawText_( SwDrawTextInfo &rInf, const bool bGrey )
         else
         {
             const OUString oldStr = rInf.GetText();
-            OUString aString( CalcCaseMap(oldStr) );
+            const OUString aString( CalcCaseMap(oldStr) );
             bool bCaseMapLengthDiffers(aString.getLength() != oldStr.getLength());
 
             if(bCaseMapLengthDiffers && rInf.GetLen())
@@ -1193,7 +1193,7 @@ void SwSubFont::DrawText_( SwDrawTextInfo &rInf, const bool bGrey )
                 sal_Int32 nOldIdx(rInf.GetIdx());
                 sal_Int32 nOldLen(rInf.GetLen());
                 const OUString aSnippet(oldStr.copy(nOldIdx, nOldLen));
-                OUString aNewText = CalcCaseMap(aSnippet);
+                const OUString aNewText = CalcCaseMap(aSnippet);
 
                 rInf.SetText( aNewText );
                 rInf.SetIdx( 0 );
@@ -1373,8 +1373,7 @@ sal_Int32 SwSubFont::GetCursorOfst_( SwDrawTextInfo& rInf )
             nCursor = pLastFont->GetCursorOfst( rInf );
         else
         {
-            OUString aTmp = CalcCaseMap( rInf.GetText() );
-            rInf.SetText( aTmp );
+            rInf.SetText( CalcCaseMap( rInf.GetText() ) );
             nCursor = pLastFont->GetCursorOfst( rInf );
         }
         rInf.SetKern( nOldKern );
commit 6ee4f63438a2ea7a56a821373679aa56814b2582
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Sun Oct 29 15:15:21 2017 +0100

    Simplify OUString and return early
    
    Change-Id: I783b3fda560cddbbf5c196d20db6323972f62402

diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index d6df70586af0..dd39f53522d8 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -270,7 +270,6 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
         {
             ScDBCollection* pUndoColl = nullptr;
 
-            OUString aNewName;
             if (eMode==SC_DB_IMPORT)
             {
                 aDocument.PreprocessDBDataUpdate();
@@ -280,11 +279,11 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
                 long nCount = 0;
                 const ScDBData* pDummy = nullptr;
                 ScDBCollection::NamedDBs& rDBs = pColl->getNamedDBs();
+                OUString aNewName;
                 do
                 {
                     ++nCount;
-                    aNewName = aImport;
-                    aNewName += OUString::number( nCount );
+                    aNewName = aImport + OUString::number( nCount );
                     pDummy = rDBs.findByUpperName(ScGlobal::pCharClass->uppercase(aNewName));
                 }
                 while (pDummy);
@@ -296,8 +295,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
             }
             else
             {
-                aNewName = STR_DB_LOCAL_NONAME;
-                pNoNameData = new ScDBData(aNewName , nTab,
+                pNoNameData = new ScDBData(STR_DB_LOCAL_NONAME, nTab,
                                 nStartCol,nStartRow, nEndCol,nEndRow,
                                 true, bHasHeader );
                 aDocument.SetAnonymousDBData(nTab, pNoNameData);
@@ -474,19 +472,13 @@ void ScDocShell::RefreshPivotTables( const ScRange& rSource )
 
 static OUString lcl_GetAreaName( ScDocument* pDoc, ScArea* pArea )
 {
-    OUString aName;
-    bool bOk = false;
     ScDBData* pData = pDoc->GetDBAtArea( pArea->nTab, pArea->nColStart, pArea->nRowStart,
                                                         pArea->nColEnd, pArea->nRowEnd );
     if (pData)
-    {
-        aName = pData->GetName();
-        bOk = true;
-    }
-
-    if (!bOk)
-        pDoc->GetName( pArea->nTab, aName );
+        return pData->GetName();
 
+    OUString aName;
+    pDoc->GetName( pArea->nTab, aName );
     return aName;
 }
 


More information about the Libreoffice-commits mailing list