[Libreoffice-commits] core.git: bridges/inc bridges/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 5 15:01:06 UTC 2019


 bridges/inc/vtablefactory.hxx                       |    7 ++++---
 bridges/source/cpp_uno/shared/cppinterfaceproxy.cxx |    8 ++++----
 bridges/source/cpp_uno/shared/vtablefactory.cxx     |   10 +++-------
 3 files changed, 11 insertions(+), 14 deletions(-)

New commits:
commit ec56174b0c83411b762b0992565e58c1ec4fc3f3
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Sep 5 14:52:13 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 5 17:00:14 2019 +0200

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

diff --git a/bridges/inc/vtablefactory.hxx b/bridges/inc/vtablefactory.hxx
index 6978e3c670b5..369ea0b903bf 100644
--- a/bridges/inc/vtablefactory.hxx
+++ b/bridges/inc/vtablefactory.hxx
@@ -26,6 +26,7 @@
 #include <sal/types.h>
 #include <typelib/typedescription.hxx>
 
+#include <memory>
 #include <unordered_map>
 
 /*See: http://people.redhat.com/drepper/selinux-mem.html*/
@@ -92,10 +93,10 @@ public:
             mapBlockToVtable).  Also, the block contains any generated code
             snippets, after the vtable itself.</p>
          */
-        Block * blocks;
+        std::unique_ptr<Block[]> blocks;
+
         Vtables()
             : count(0)
-            , blocks(nullptr)
         {
         }
     };
@@ -107,7 +108,7 @@ public:
     /** Given an interface type description, return its corresponding vtable
         structure.
      */
-    Vtables getVtables(typelib_InterfaceTypeDescription * type);
+    const Vtables& getVtables(typelib_InterfaceTypeDescription * type);
 
     // This function is not defined in the generic part, but instead has to be
     // defined individually for each CPP--UNO bridge:
diff --git a/bridges/source/cpp_uno/shared/cppinterfaceproxy.cxx b/bridges/source/cpp_uno/shared/cppinterfaceproxy.cxx
index 39afb083b9bd..bb5f268179a7 100644
--- a/bridges/source/cpp_uno/shared/cppinterfaceproxy.cxx
+++ b/bridges/source/cpp_uno/shared/cppinterfaceproxy.cxx
@@ -100,18 +100,18 @@ com::sun::star::uno::XInterface * CppInterfaceProxy::create(
 {
     typelib_typedescription_complete(
         reinterpret_cast< typelib_TypeDescription ** >(&pTypeDescr));
-    bridges::cpp_uno::shared::VtableFactory::Vtables aVtables(
+    const bridges::cpp_uno::shared::VtableFactory::Vtables& rVtables(
         getVtableFactory()->getVtables(pTypeDescr));
     std::unique_ptr< char[] > pMemory(
         new char[
             sizeof (CppInterfaceProxy)
-            + (aVtables.count - 1) * sizeof (void **)]);
+            + (rVtables.count - 1) * sizeof (void **)]);
     new(pMemory.get()) CppInterfaceProxy(pBridge, pUnoI, pTypeDescr, rOId);
     CppInterfaceProxy * pProxy = reinterpret_cast< CppInterfaceProxy * >(
         pMemory.release());
-    for (sal_Int32 i = 0; i < aVtables.count; ++i) {
+    for (sal_Int32 i = 0; i < rVtables.count; ++i) {
         pProxy->vtables[i] = VtableFactory::mapBlockToVtable(
-            aVtables.blocks[i].start);
+            rVtables.blocks[i].start);
     }
     return castProxyToInterface(pProxy);
 }
diff --git a/bridges/source/cpp_uno/shared/vtablefactory.cxx b/bridges/source/cpp_uno/shared/vtablefactory.cxx
index c71ae52ae14e..70187cbd2fe7 100644
--- a/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -186,13 +186,12 @@ VtableFactory::~VtableFactory() {
             for (sal_Int32 j = 0; j < rEntry.second.count; ++j) {
                 freeBlock(rEntry.second.blocks[j]);
             }
-            delete[] rEntry.second.blocks;
         }
     }
     rtl_arena_destroy(m_arena);
 }
 
-VtableFactory::Vtables VtableFactory::getVtables(
+const VtableFactory::Vtables& VtableFactory::getVtables(
     typelib_InterfaceTypeDescription * type)
 {
     OUString name(type->aBase.pTypeName);
@@ -204,14 +203,11 @@ VtableFactory::Vtables VtableFactory::getVtables(
         Vtables vtables;
         assert(blocks.size() <= SAL_MAX_INT32);
         vtables.count = static_cast< sal_Int32 >(blocks.size());
-        std::unique_ptr< Block[] > guardedBlocks(
-            new Block[vtables.count]);
-        vtables.blocks = guardedBlocks.get();
+        vtables.blocks.reset(new Block[vtables.count]);
         for (sal_Int32 j = 0; j < vtables.count; ++j) {
             vtables.blocks[j] = blocks[j];
         }
-        i = m_map.emplace(name, vtables).first;
-        guardedBlocks.release();
+        i = m_map.emplace(name, std::move(vtables)).first;
         blocks.unguard();
     }
     return i->second;


More information about the Libreoffice-commits mailing list