summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-10-01 07:03:47 -0400
committerAshod Nakashian <ashnakash@gmail.com>2019-12-26 03:41:46 +0100
commit2be9633f3c1a145255d979a4d63aa957db5bff10 (patch)
treec004279f8333e295e52483692d07060c9d072bc5 /sfx2
parent6ffcbd6e8e07989af0dac07e2e43dfd96693dd7a (diff)
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@gmail.com> (cherry picked from commit b6a16d2242cbee533ef46dd171a89ddd44f3af62) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85801 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/DocumentMetadataAccess.cxx67
1 files changed, 50 insertions, 17 deletions
diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx
index be9a472014d0..eb20bcbf6eea 100644
--- a/sfx2/source/doc/DocumentMetadataAccess.cxx
+++ b/sfx2/source/doc/DocumentMetadataAccess.cxx
@@ -446,6 +446,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,
@@ -885,26 +927,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