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

Noel Grandin noel.grandin at collabora.co.uk
Mon Apr 10 06:54:08 UTC 2017


 ucb/source/inc/regexpmap.hxx |   67 ++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 38 deletions(-)

New commits:
commit c6dc4ba419c24c244be6beffca2d5689697f37a0
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 7 15:05:26 2017 +0200

    loplugin:inlinefields in ucb_impl::RegexpMap
    
    Change-Id: Id8cf4a9e7f85048dac37fc1256427214abe3ac8c
    Reviewed-on: https://gerrit.libreoffice.org/36265
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/inc/regexpmap.hxx b/ucb/source/inc/regexpmap.hxx
index d1658e7f0f95..aef7c8638411 100644
--- a/ucb/source/inc/regexpmap.hxx
+++ b/ucb/source/inc/regexpmap.hxx
@@ -386,29 +386,27 @@ public:
     Val const * map(OUString const & rString) const;
 
 private:
-    RegexpMapImpl< Val > * m_pImpl;
+    RegexpMapImpl< Val > m_aImpl;
 };
 
 template< typename Val >
-RegexpMap< Val >::RegexpMap():
-    m_pImpl(new RegexpMapImpl< Val >)
+RegexpMap< Val >::RegexpMap()
 {}
 
 template< typename Val >
 RegexpMap< Val >::RegexpMap(RegexpMap const & rOther):
-    m_pImpl(new RegexpMapImpl< Val >(*rOther.m_pImpl))
+    m_aImpl(rOther.m_pImpl)
 {}
 
 template< typename Val >
 RegexpMap< Val >::~RegexpMap()
 {
-    delete m_pImpl;
 }
 
 template< typename Val >
 RegexpMap< Val > & RegexpMap< Val >::operator =(RegexpMap const & rOther)
 {
-    *m_pImpl = *rOther.m_pImpl;
+    m_aImpl = rOther.m_aImpl;
     return *this;
 }
 
@@ -419,15 +417,15 @@ void RegexpMap< Val >::add(rtl::OUString const & rKey, Val const & rValue)
 
     if (aRegexp.isDefault())
     {
-        if (m_pImpl->m_pDefault)
+        if (m_aImpl.m_pDefault)
         {
             return;
         }
-        m_pImpl->m_pDefault.reset( new Entry< Val >(aRegexp, rValue) );
+        m_aImpl.m_pDefault.reset( new Entry< Val >(aRegexp, rValue) );
     }
     else
     {
-        List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()];
+        List< Val > & rTheList = m_aImpl.m_aList[aRegexp.getKind()];
 
         typename List< Val >::iterator aEnd(rTheList.end());
         for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt)
@@ -449,36 +447,36 @@ typename RegexpMap< Val >::iterator RegexpMap< Val >::find(rtl::OUString const &
 
     if (aRegexp.isDefault())
     {
-        if (m_pImpl->m_pDefault)
-            return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
+        if (m_aImpl.m_pDefault)
+            return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl,
                                                                      true));
     }
     else
     {
-        List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()];
+        List< Val > & rTheList = m_aImpl.m_aList[aRegexp.getKind()];
 
         typename List< Val > ::iterator aEnd(rTheList.end());
         for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt)
             if (aIt->m_aRegexp == aRegexp)
                 return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(
-                                                    m_pImpl,
+                                                    &m_aImpl,
                                                     aRegexp.getKind(), aIt));
     }
 
-    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false));
+    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl, false));
 }
 
 template< typename Val >
 void RegexpMap< Val >::erase(iterator const & rPos)
 {
-    if (rPos.m_pImpl->getMap() == m_pImpl)
+    if (rPos.m_pImpl->getMap() == &m_aImpl)
     {
         if (rPos.m_pImpl->getList() == -1)
         {
-            m_pImpl->m_pDefault.reset();
+            m_aImpl.m_pDefault.reset();
         }
         else
-            m_pImpl->m_aList[rPos.m_pImpl->getList()].
+            m_aImpl.m_aList[rPos.m_pImpl->getList()].
                          erase(rPos.m_pImpl->getIndex());
     }
 }
@@ -486,36 +484,36 @@ void RegexpMap< Val >::erase(iterator const & rPos)
 template< typename Val >
 typename RegexpMap< Val >::iterator RegexpMap< Val >::begin()
 {
-    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, true));
+    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl, true));
 }
 
 template< typename Val >
 typename RegexpMap< Val >::const_iterator RegexpMap< Val >::begin() const
 {
-    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
+    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl,
                                                                   true));
 }
 
 template< typename Val >
 typename RegexpMap< Val >::iterator RegexpMap< Val >::end()
 {
-    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false));
+    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl, false));
 }
 
 template< typename Val >
 typename RegexpMap< Val >::const_iterator RegexpMap< Val >::end() const
 {
-    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
+    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(&m_aImpl,
                                                                   false));
 }
 
 template< typename Val >
 typename RegexpMap< Val >::size_type RegexpMap< Val >::size() const
 {
-    return (m_pImpl->m_pDefault ? 1 : 0)
-               + m_pImpl->m_aList[Regexp::KIND_PREFIX].size()
-               + m_pImpl->m_aList[Regexp::KIND_AUTHORITY].size()
-               + m_pImpl->m_aList[Regexp::KIND_DOMAIN].size();
+    return (m_aImpl.m_pDefault ? 1 : 0)
+               + m_aImpl.m_aList[Regexp::KIND_PREFIX].size()
+               + m_aImpl.m_aList[Regexp::KIND_AUTHORITY].size()
+               + m_aImpl.m_aList[Regexp::KIND_DOMAIN].size();
 }
 
 template< typename Val >
@@ -523,7 +521,7 @@ Val const * RegexpMap< Val >::map(rtl::OUString const & rString) const
 {
     for (int n = Regexp::KIND_DOMAIN; n >= Regexp::KIND_PREFIX; --n)
     {
-        List< Val > const & rTheList = m_pImpl->m_aList[n];
+        List< Val > const & rTheList = m_aImpl.m_aList[n];
 
         typename List< Val >::const_iterator aEnd(rTheList.end());
         for (typename List< Val >::const_iterator aIt(rTheList.begin()); aIt != aEnd;
@@ -531,9 +529,9 @@ Val const * RegexpMap< Val >::map(rtl::OUString const & rString) const
             if (aIt->m_aRegexp.matches(rString))
                 return &aIt->m_aValue;
     }
-    if (m_pImpl->m_pDefault
-        && m_pImpl->m_pDefault->m_aRegexp.matches(rString))
-        return &m_pImpl->m_pDefault->m_aValue;
+    if (m_aImpl.m_pDefault
+        && m_aImpl.m_pDefault->m_aRegexp.matches(rString))
+        return &m_aImpl.m_pDefault->m_aValue;
     return 0;
 }
 
commit 340d58f2231bdbd16fa5cf14d7085a7d8b0ade09
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 7 15:01:28 2017 +0200

    use unique_ptr in RegexpMapImpl
    
    Change-Id: I150bd441281305346bf6be1844894ae857dd50f7
    Reviewed-on: https://gerrit.libreoffice.org/36264
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/inc/regexpmap.hxx b/ucb/source/inc/regexpmap.hxx
index e9475f8a9684..d1658e7f0f95 100644
--- a/ucb/source/inc/regexpmap.hxx
+++ b/ucb/source/inc/regexpmap.hxx
@@ -23,6 +23,7 @@
 #include "sal/config.h"
 
 #include <list>
+#include <memory>
 
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
@@ -73,11 +74,7 @@ template< typename Val >
 struct RegexpMapImpl
 {
     List< Val > m_aList[Regexp::KIND_DOMAIN + 1];
-    Entry< Val > * m_pDefault;
-
-    RegexpMapImpl(): m_pDefault(nullptr) {}
-
-    ~RegexpMapImpl() { delete m_pDefault; }
+    std::unique_ptr<Entry< Val >> m_pDefault;
 };
 
 
@@ -426,7 +423,7 @@ void RegexpMap< Val >::add(rtl::OUString const & rKey, Val const & rValue)
         {
             return;
         }
-        m_pImpl->m_pDefault = new Entry< Val >(aRegexp, rValue);
+        m_pImpl->m_pDefault.reset( new Entry< Val >(aRegexp, rValue) );
     }
     else
     {
@@ -478,11 +475,7 @@ void RegexpMap< Val >::erase(iterator const & rPos)
     {
         if (rPos.m_pImpl->getList() == -1)
         {
-            if (m_pImpl->m_pDefault)
-            {
-                delete m_pImpl->m_pDefault;
-                m_pImpl->m_pDefault = 0;
-            }
+            m_pImpl->m_pDefault.reset();
         }
         else
             m_pImpl->m_aList[rPos.m_pImpl->getList()].


More information about the Libreoffice-commits mailing list