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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Dec 3 07:11:20 UTC 2018


 sfx2/source/doc/DocumentMetadataAccess.cxx |   67 +++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 17 deletions(-)

New commits:
commit 8c84672e93a6bcdc53d93e7a3c8321684ed36736
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Mon Oct 1 07:03:47 2018 -0400
Commit:     Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Mon Dec 3 08:10:58 2018 +0100

    sfx2: Combine metadata graph lookup and filtering
    
    The graph lookup is suprisingly costly and so is
    filtering. By specializing the lookup with filtering
    the logic is more readable and slightly faster (~35%
    in debug build).
    
    Change-Id: Id35a562c76a84a81362f47b61ed67fb74d0a6dc7
    Reviewed-on: https://gerrit.libreoffice.org/63001
    Tested-by: Jenkins
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx
index 04c3fb4ea963..980e6ec06d37 100644
--- a/sfx2/source/doc/DocumentMetadataAccess.cxx
+++ b/sfx2/source/doc/DocumentMetadataAccess.cxx
@@ -417,6 +417,48 @@ isPartOfType(struct DocumentMetadataAccess_Impl const & i_rImpl,
     }
 }
 
+static ::std::vector<uno::Reference<rdf::XURI>>
+getAllParts(struct DocumentMetadataAccess_Impl const& i_rImpl,
+            const uno::Reference<rdf::XURI>& i_xType)
+{
+    ::std::vector<uno::Reference<rdf::XURI>> ret;
+    try
+    {
+        const uno::Reference<container::XEnumeration> xEnum(
+            i_rImpl.m_xManifest->getStatements(i_rImpl.m_xBaseURI.get(),
+                                               getURI<rdf::URIs::PKG_HASPART>(i_rImpl.m_xContext),
+                                               nullptr),
+            uno::UNO_SET_THROW);
+        while (xEnum->hasMoreElements())
+        {
+            rdf::Statement stmt;
+            if (!(xEnum->nextElement() >>= stmt))
+            {
+                throw uno::RuntimeException();
+            }
+            const uno::Reference<rdf::XURI> xPart(stmt.Object, uno::UNO_QUERY);
+            if (!xPart.is())
+                continue;
+
+            const uno::Reference<container::XEnumeration> xEnum2(
+                i_rImpl.m_xManifest->getStatements(
+                    xPart.get(), getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), i_xType.get()),
+                uno::UNO_SET_THROW);
+            if (xEnum2->hasMoreElements())
+                ret.emplace_back(xPart);
+        }
+        return ret;
+    }
+    catch (const uno::RuntimeException&)
+    {
+        throw;
+    }
+    catch (const uno::Exception& e)
+    {
+        throw lang::WrappedTargetRuntimeException("getAllParts: exception", nullptr,
+                                                  uno::makeAny(e));
+    }
+}
 
 static ucb::InteractiveAugmentedIOException
 mkException( OUString const & i_rMessage,
@@ -856,26 +898,17 @@ DocumentMetadataAccess::getElementByURI(
     return getElementByMetadataReference( beans::StringPair(path, idref) );
 }
 
-
-uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
-DocumentMetadataAccess::getMetadataGraphsWithType(
-    const uno::Reference<rdf::XURI> & i_xType)
+uno::Sequence<uno::Reference<rdf::XURI>> SAL_CALL
+DocumentMetadataAccess::getMetadataGraphsWithType(const uno::Reference<rdf::XURI>& i_xType)
 {
-    if (!i_xType.is()) {
-        throw lang::IllegalArgumentException(
-            "DocumentMetadataAccess::getMetadataGraphsWithType: "
-            "type is null", *this, 0);
+    if (!i_xType.is())
+    {
+        throw lang::IllegalArgumentException("DocumentMetadataAccess::getMetadataGraphsWithType: "
+                                             "type is null",
+                                             *this, 0);
     }
 
-    ::std::vector< uno::Reference< rdf::XURI > > ret;
-    const ::std::vector< uno::Reference< rdf::XURI > > parts(
-        getAllParts(*m_pImpl) );
-    ::std::remove_copy_if(parts.begin(), parts.end(),
-        ::std::back_inserter(ret),
-        [this, &i_xType](uno::Reference< rdf::XURI > aPart) {
-            return !isPartOfType(*m_pImpl, aPart, i_xType);
-        } );
-    return ::comphelper::containerToSequence(ret);
+    return ::comphelper::containerToSequence(getAllParts(*m_pImpl, i_xType));
 }
 
 uno::Reference<rdf::XURI> SAL_CALL


More information about the Libreoffice-commits mailing list