[Libreoffice-commits] core.git: unoxml/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 23 14:59:11 UTC 2020


 unoxml/source/rdf/librdf_repository.cxx |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 5fd05b2d4a61af0e72cf75f465c4f6ad7b2f4cc9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jan 23 15:03:17 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jan 23 15:58:38 2020 +0100

    simplify NodeArray code
    
    no need to use shared_ptr here
    
    Change-Id: Ib40929c4378e110eb42261df36b4add969416cb0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87269
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/unoxml/source/rdf/librdf_repository.cxx b/unoxml/source/rdf/librdf_repository.cxx
index 39db47b51b99..68ba3135512f 100644
--- a/unoxml/source/rdf/librdf_repository.cxx
+++ b/unoxml/source/rdf/librdf_repository.cxx
@@ -634,17 +634,20 @@ librdf_QuerySelectResult::hasMoreElements()
     return !librdf_query_results_finished(m_pQueryResult.get());
 }
 
-class NodeArrayDeleter
+struct NodeArray
 {
-    const int m_Count;
+    int m_Count;
+    std::unique_ptr<librdf_node*[]> m_pNodes;
 
-public:
-    explicit NodeArrayDeleter(int i_Count) : m_Count(i_Count) { }
+    NodeArray(int cnt) : m_Count(cnt), m_pNodes(new librdf_node*[cnt])
+    {
+        for (int i = 0; i < cnt; ++i)
+            m_pNodes[i] = nullptr;
+    }
 
-    void operator() (librdf_node** io_pArray) const throw ()
+    ~NodeArray() throw ()
     {
-        std::for_each(io_pArray, io_pArray + m_Count, safe_librdf_free_node);
-        delete[] io_pArray;
+        std::for_each(m_pNodes.get(), m_pNodes.get() + m_Count, safe_librdf_free_node);
     }
 };
 
@@ -657,13 +660,9 @@ librdf_QuerySelectResult::nextElement()
     }
     sal_Int32 count(m_BindingNames.getLength());
     OSL_ENSURE(count >= 0, "negative length?");
-    std::shared_ptr<librdf_node*> const pNodes(new librdf_node*[count],
-        NodeArrayDeleter(count));
-    for (int i = 0; i < count; ++i) {
-        pNodes.get()[i] = nullptr;
-    }
+    NodeArray aNodes(count);
     if (librdf_query_results_get_bindings(m_pQueryResult.get(), nullptr,
-                pNodes.get()))
+                aNodes.m_pNodes.get()))
     {
         rdf::QueryException e(
             "librdf_QuerySelectResult::nextElement: "
@@ -675,7 +674,7 @@ librdf_QuerySelectResult::nextElement()
     }
     uno::Sequence< uno::Reference< rdf::XNode > > ret(count);
     for (int i = 0; i < count; ++i) {
-        ret[i] = m_xRep->getTypeConverter().convertToXNode(pNodes.get()[i]);
+        ret[i] = m_xRep->getTypeConverter().convertToXNode(aNodes.m_pNodes[i]);
     }
     // NB: this will invalidate current item.
     librdf_query_results_next(m_pQueryResult.get());


More information about the Libreoffice-commits mailing list