sfx2/source/doc/DocumentMetadataAccess.cxx | 67 +++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 17 deletions(-)
New commits: commit 2be9633f3c1a145255d979a4d63aa957db5bff10 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Mon Oct 1 07:03:47 2018 -0400 Commit: Ashod Nakashian <ashnak...@gmail.com> CommitDate: Thu Dec 26 03:41:46 2019 +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 <ashnak...@gmail.com> (cherry picked from commit b6a16d2242cbee533ef46dd171a89ddd44f3af62) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85801 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits