[Libreoffice-commits] core.git: 2 commits - include/toolkit toolkit/source tools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 18 07:08:46 UTC 2018


 include/toolkit/controls/stdtabcontrollermodel.hxx |    8 ---
 toolkit/source/controls/stdtabcontroller.cxx       |   42 ++++++++++----------
 tools/source/inet/inetmime.cxx                     |   44 +++++++++------------
 3 files changed, 42 insertions(+), 52 deletions(-)

New commits:
commit 1d6366fc9aac6f9645f35bcdc784aeb46e20ba47
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 17 14:32:29 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 09:08:35 2018 +0200

    loplugin:useuniqueptr in StdTabController::autoTabOrder
    
    Change-Id: I67c2283974eb71978beaf265f821fd2c5c5ae55c
    Reviewed-on: https://gerrit.libreoffice.org/60626
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/toolkit/controls/stdtabcontrollermodel.hxx b/include/toolkit/controls/stdtabcontrollermodel.hxx
index 19884f505229..2f73c1c8af56 100644
--- a/include/toolkit/controls/stdtabcontrollermodel.hxx
+++ b/include/toolkit/controls/stdtabcontrollermodel.hxx
@@ -69,14 +69,6 @@ struct UnoControlModelEntry
     };
 };
 
-struct ComponentEntry
-{
-    css::awt::XWindow*     pComponent;
-    Point                               aPos;
-};
-
-typedef ::std::vector< ComponentEntry* > ComponentEntryList;
-
 #define CONTROLPOS_NOTFOUND 0xFFFFFFFF
 
 class StdTabControllerModel final : public css::awt::XTabControllerModel,
diff --git a/toolkit/source/controls/stdtabcontroller.cxx b/toolkit/source/controls/stdtabcontroller.cxx
index d337b972ad53..d9bcc5928ecb 100644
--- a/toolkit/source/controls/stdtabcontroller.cxx
+++ b/toolkit/source/controls/stdtabcontroller.cxx
@@ -231,6 +231,12 @@ Sequence< Reference< XControl > > StdTabController::getControls(  )
     return aSeq;
 }
 
+struct ComponentEntry
+{
+    css::awt::XWindow*  pComponent;
+    ::Point             aPos;
+};
+
 void StdTabController::autoTabOrder(  )
 {
     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
@@ -255,43 +261,39 @@ void StdTabController::autoTabOrder(  )
     Reference< XWindow > * pComponents = aCompSeq.getArray();
 
     // insert sort algorithm
-    ComponentEntryList aCtrls;
-    size_t n;
-    for ( n = 0; n < nCtrls; n++ )
+    std::vector< ComponentEntry > aCtrls;
+    aCtrls.reserve(nCtrls);
+    for ( size_t n = 0; n < nCtrls; n++ )
     {
         XWindow* pC = pComponents[n].get();
-        ComponentEntry* pE = new ComponentEntry;
-        pE->pComponent = pC;
+        ComponentEntry newEntry;
+        newEntry.pComponent = pC;
         awt::Rectangle aPosSize = pC->getPosSize();
-        pE->aPos.setX( aPosSize.X );
-        pE->aPos.setY( aPosSize.Y );
+        newEntry.aPos.setX( aPosSize.X );
+        newEntry.aPos.setY( aPosSize.Y );
 
-        ComponentEntryList::size_type nPos;
+        decltype(aCtrls)::size_type nPos;
         for ( nPos = 0; nPos < aCtrls.size(); nPos++ )
         {
-            ComponentEntry* pEntry = aCtrls[ nPos ];
-            if ( ( pEntry->aPos.Y() > pE->aPos.Y() ) ||
-                 ( ( pEntry->aPos.Y() == pE->aPos.Y() ) && ( pEntry->aPos.X() > pE->aPos.X() ) ) )
+            ComponentEntry& rEntry = aCtrls[ nPos ];
+            if ( ( rEntry.aPos.Y() > newEntry.aPos.Y() ) ||
+                 ( ( rEntry.aPos.Y() == newEntry.aPos.Y() ) && ( rEntry.aPos.X() > newEntry.aPos.X() ) ) )
                     break;
         }
         if ( nPos < aCtrls.size() ) {
-            ComponentEntryList::iterator it = aCtrls.begin();
-            ::std::advance( it, nPos );
-            aCtrls.insert( it, pE );
+            aCtrls.insert( aCtrls.begin() + nPos, newEntry );
         } else {
-            aCtrls.push_back( pE );
+            aCtrls.push_back( newEntry );
         }
     }
 
     Sequence< Reference< XControlModel > > aNewSeq( nCtrls );
-    for ( n = 0; n < nCtrls; n++ )
+    for ( size_t n = 0; n < nCtrls; n++ )
     {
-        ComponentEntry* pE = aCtrls[ n ];
-        Reference< XControl >  xUC( pE->pComponent, UNO_QUERY );
+        ComponentEntry& rEntry = aCtrls[ n ];
+        Reference< XControl >  xUC( rEntry.pComponent, UNO_QUERY );
         aNewSeq.getArray()[n] = xUC->getModel();
-        delete pE;
     }
-    aCtrls.clear();
 
     mxModel->setControlModels( aNewSeq );
 }
commit b225295d68f5e868595b74342d41338c49d33589
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Sep 17 13:56:14 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 09:08:23 2018 +0200

    loplugin:useuniqueptr in convertToUnicode
    
    Change-Id: I1d4379350793c3c245952793af5defeea84075b3
    Reviewed-on: https://gerrit.libreoffice.org/60624
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index aee940a8bc7a..1f8cb5196d3e 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -94,7 +94,7 @@ inline bool isMIMECharsetEncoding(rtl_TextEncoding eEncoding)
     return rtl_isOctetTextEncoding(eEncoding);
 }
 
-sal_Unicode * convertToUnicode(const sal_Char * pBegin,
+std::unique_ptr<sal_Unicode[]> convertToUnicode(const sal_Char * pBegin,
                                          const sal_Char * pEnd,
                                          rtl_TextEncoding eEncoding,
                                          sal_Size & rSize)
@@ -105,15 +105,15 @@ sal_Unicode * convertToUnicode(const sal_Char * pBegin,
         = rtl_createTextToUnicodeConverter(eEncoding);
     rtl_TextToUnicodeContext hContext
         = rtl_createTextToUnicodeContext(hConverter);
-    sal_Unicode * pBuffer;
+    std::unique_ptr<sal_Unicode[]> pBuffer;
     sal_uInt32 nInfo;
     for (sal_Size nBufferSize = pEnd - pBegin;;
          nBufferSize += nBufferSize / 3 + 1)
     {
-        pBuffer = new sal_Unicode[nBufferSize];
+        pBuffer.reset(new sal_Unicode[nBufferSize]);
         sal_Size nSrcCvtBytes;
         rSize = rtl_convertTextToUnicode(
-                    hConverter, hContext, pBegin, pEnd - pBegin, pBuffer,
+                    hConverter, hContext, pBegin, pEnd - pBegin, pBuffer.get(),
                     nBufferSize,
                     RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
                         | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
@@ -121,20 +121,19 @@ sal_Unicode * convertToUnicode(const sal_Char * pBegin,
                     &nInfo, &nSrcCvtBytes);
         if (nInfo != RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL)
             break;
-        delete[] pBuffer;
+        pBuffer.reset();
         rtl_resetTextToUnicodeContext(hConverter, hContext);
     }
     rtl_destroyTextToUnicodeContext(hConverter, hContext);
     rtl_destroyTextToUnicodeConverter(hConverter);
     if (nInfo != 0)
     {
-        delete[] pBuffer;
-        pBuffer = nullptr;
+        pBuffer.reset();
     }
     return pBuffer;
 }
 
-sal_Char * convertFromUnicode(const sal_Unicode * pBegin,
+std::unique_ptr<sal_Char[]> convertFromUnicode(const sal_Unicode * pBegin,
                                         const sal_Unicode * pEnd,
                                         rtl_TextEncoding eEncoding,
                                         sal_Size & rSize)
@@ -145,15 +144,15 @@ sal_Char * convertFromUnicode(const sal_Unicode * pBegin,
         = rtl_createUnicodeToTextConverter(eEncoding);
     rtl_UnicodeToTextContext hContext
         = rtl_createUnicodeToTextContext(hConverter);
-    sal_Char * pBuffer;
+    std::unique_ptr<sal_Char[]> pBuffer;
     sal_uInt32 nInfo;
     for (sal_Size nBufferSize = pEnd - pBegin;;
          nBufferSize += nBufferSize / 3 + 1)
     {
-        pBuffer = new sal_Char[nBufferSize];
+        pBuffer.reset(new sal_Char[nBufferSize]);
         sal_Size nSrcCvtBytes;
         rSize = rtl_convertUnicodeToText(
-                    hConverter, hContext, pBegin, pEnd - pBegin, pBuffer,
+                    hConverter, hContext, pBegin, pEnd - pBegin, pBuffer.get(),
                     nBufferSize,
                     RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
                         | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
@@ -162,15 +161,14 @@ sal_Char * convertFromUnicode(const sal_Unicode * pBegin,
                     &nInfo, &nSrcCvtBytes);
         if (nInfo != RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL)
             break;
-        delete[] pBuffer;
+        pBuffer.reset();
         rtl_resetUnicodeToTextContext(hConverter, hContext);
     }
     rtl_destroyUnicodeToTextContext(hConverter, hContext);
     rtl_destroyUnicodeToTextConverter(hConverter);
     if (nInfo != 0)
     {
-        delete[] pBuffer;
-        pBuffer = nullptr;
+        pBuffer.reset();
     }
     return pBuffer;
 }
@@ -294,14 +292,13 @@ bool translateUTF8Char(const sal_Char *& rBegin,
         sal_Unicode aUTF16[2];
         const sal_Unicode * pUTF16End = putUTF32Character(aUTF16, nUCS4);
         sal_Size nSize;
-        sal_Char * pBuffer = convertFromUnicode(aUTF16, pUTF16End, eEncoding,
+        std::unique_ptr<sal_Char[]> pBuffer = convertFromUnicode(aUTF16, pUTF16End, eEncoding,
                                                 nSize);
         if (!pBuffer)
             return false;
         DBG_ASSERT(nSize == 1,
                    "translateUTF8Char(): Bad conversion");
-        rCharacter = *pBuffer;
-        delete[] pBuffer;
+        rCharacter = *pBuffer.get();
     }
     rBegin = p;
     return true;
@@ -384,7 +381,7 @@ bool parseParameters(ParameterList const & rInput,
             do
             {
                 sal_Size nSize;
-                sal_Unicode * pUnicode
+                std::unique_ptr<sal_Unicode[]> pUnicode
                     = convertToUnicode(itNext->m_aValue.getStr(),
                                                  itNext->m_aValue.getStr()
                                                      + itNext->m_aValue.getLength(),
@@ -403,8 +400,7 @@ bool parseParameters(ParameterList const & rInput,
                     bBadEncoding = true;
                     break;
                 }
-                aValue.append(pUnicode, static_cast<sal_Int32>(nSize));
-                delete[] pUnicode;
+                aValue.append(pUnicode.get(), static_cast<sal_Int32>(nSize));
                 ++itNext;
             }
             while (itNext != rInput.end() && itNext->m_nSection != 0);
@@ -1395,7 +1391,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
 
             bEncodedWord = bEncodedWord && q != pEnd && *q++ == '=';
 
-            sal_Unicode * pUnicodeBuffer = nullptr;
+            std::unique_ptr<sal_Unicode[]> pUnicodeBuffer;
             sal_Size nUnicodeSize = 0;
             if (bEncodedWord)
             {
@@ -1403,7 +1399,7 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
                     = convertToUnicode(sText.getStr(),
                                        sText.getStr() + sText.getLength(),
                                        eCharsetEncoding, nUnicodeSize);
-                if (pUnicodeBuffer == nullptr)
+                if (!pUnicodeBuffer)
                     bEncodedWord = false;
             }
 
@@ -1411,9 +1407,9 @@ OUString INetMIME::decodeHeaderFieldBody(const OString& rBody)
             {
                 appendISO88591(sDecoded, pCopyBegin, pWSPBegin);
                 sDecoded.append(
-                    pUnicodeBuffer,
+                    pUnicodeBuffer.get(),
                     static_cast< sal_Int32 >(nUnicodeSize));
-                delete[] pUnicodeBuffer;
+                pUnicodeBuffer.reset();
                 p = q;
                 pCopyBegin = p;
 


More information about the Libreoffice-commits mailing list