xmloff/source/text/txthints.hxx | 54 ++++++++++++++++++++++++++++++++++++ xmloff/source/text/txtparai.cxx | 60 ++++++++++------------------------------ xmloff/source/text/txtparai.hxx | 4 +- 3 files changed, 71 insertions(+), 47 deletions(-)
New commits: commit da278e421909653ba85054daf6103991e56ffa26 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jun 24 12:04:57 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jun 24 18:31:56 2024 +0200 flatten XMLParaContext a little to avoid pointer-chasing in some hot methods Change-Id: Ie0dc1e47628a8ae1279abe2e95894dabae82f3ed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169454 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/xmloff/source/text/txthints.hxx b/xmloff/source/text/txthints.hxx new file mode 100644 index 000000000000..235a6c97e91b --- /dev/null +++ b/xmloff/source/text/txthints.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <memory> +#include <unordered_map> +#include <vector> + +class XMLHint_Impl; +class XMLIndexMarkHint_Impl; + +class XMLHints_Impl +{ +private: + std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints; + std::unordered_map<OUString, XMLIndexMarkHint_Impl*> m_IndexHintsById; + css::uno::Reference<css::uno::XInterface> m_xCrossRefHeadingBookmark; + +public: + void push_back(std::unique_ptr<XMLHint_Impl> pHint); + + void push_back(std::unique_ptr<XMLIndexMarkHint_Impl> pHint); + + std::vector<std::unique_ptr<XMLHint_Impl>> const& GetHints() const { return m_Hints; } + + XMLIndexMarkHint_Impl* GetIndexHintById(const OUString& sID) + { + auto it = m_IndexHintsById.find(sID); + return it == m_IndexHintsById.end() ? nullptr : it->second; + } + + css::uno::Reference<css::uno::XInterface>& GetCrossRefHeadingBookmark() + { + return m_xCrossRefHeadingBookmark; + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index e6c4fa3bd8f5..b22939eb1a39 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -19,9 +19,7 @@ #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> -#include <memory> #include <string_view> -#include <vector> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> @@ -70,43 +68,15 @@ using namespace ::xmloff::token; using ::com::sun::star::container::XEnumerationAccess; using ::com::sun::star::container::XEnumeration; -class XMLHints_Impl +void XMLHints_Impl::push_back(std::unique_ptr<XMLIndexMarkHint_Impl> pHint) { -private: - - std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints; - std::unordered_map<OUString, XMLIndexMarkHint_Impl*> m_IndexHintsById; - uno::Reference<uno::XInterface> m_xCrossRefHeadingBookmark; - -public: - void push_back(std::unique_ptr<XMLHint_Impl> pHint) - { - m_Hints.push_back(std::move(pHint)); - } - - void push_back(std::unique_ptr<XMLIndexMarkHint_Impl> pHint) - { - m_IndexHintsById.emplace(pHint->GetID(), pHint.get()); - m_Hints.push_back(std::move(pHint)); - } - - std::vector<std::unique_ptr<XMLHint_Impl>> const& GetHints() const - { - return m_Hints; - } - - XMLIndexMarkHint_Impl* GetIndexHintById(const OUString& sID) - { - auto it = m_IndexHintsById.find(sID); - return it == m_IndexHintsById.end() ? nullptr : it->second; - } - - uno::Reference<uno::XInterface> & GetCrossRefHeadingBookmark() - { - return m_xCrossRefHeadingBookmark; - } -}; - + m_IndexHintsById.emplace(pHint->GetID(), pHint.get()); + m_Hints.push_back(std::move(pHint)); +} +void XMLHints_Impl::push_back(std::unique_ptr<XMLHint_Impl> pHint) +{ + m_Hints.push_back(std::move(pHint)); +} XMLCharContext::XMLCharContext( SvXMLImport& rImport, @@ -1849,14 +1819,14 @@ void XMLParaContext::endFastElement(sal_Int32 ) } } - if (m_xHints) + if (m_oHints) { bool bEmptyHints = false; if (auto xCompare = xTxtImport->GetText().query<text::XTextRangeCompare>()) { try { - for (const auto& pHint : m_xHints->GetHints()) + for (const auto& pHint : m_oHints->GetHints()) { if (xCompare->compareRegionStarts(pHint->GetStart(), pHint->GetEnd()) == 0) { @@ -1882,7 +1852,7 @@ void XMLParaContext::endFastElement(sal_Int32 ) { xCursorProps->setPropertyValue(u"NoFormatAttr"_ustr, uno::Any(true)); } - for (const auto & i : m_xHints->GetHints()) + for (const auto & i : m_oHints->GetHints()) { XMLHint_Impl *const pHint = i.get(); xAttrCursor->gotoRange( pHint->GetStart(), false ); @@ -2026,18 +1996,18 @@ void XMLParaContext::endFastElement(sal_Int32 ) xCursorProps->setPropertyValue(u"NoFormatAttr"_ustr, uno::Any(false)); } } - m_xHints.reset(); + m_oHints.reset(); } css::uno::Reference< css::xml::sax::XFastContextHandler > XMLParaContext::createFastChildContext( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - if (!m_xHints) - m_xHints.reset(new XMLHints_Impl); + if (!m_oHints) + m_oHints.emplace(); return XMLImpSpanContext_Impl::CreateSpanContext( GetImport(), nElement, xAttrList, - *m_xHints, bIgnoreLeadingSpace, + *m_oHints, bIgnoreLeadingSpace, nStarFontsConvFlags); } diff --git a/xmloff/source/text/txtparai.hxx b/xmloff/source/text/txtparai.hxx index fed2690cb429..cfe9408d6648 100644 --- a/xmloff/source/text/txtparai.hxx +++ b/xmloff/source/text/txtparai.hxx @@ -22,8 +22,8 @@ #include <com/sun/star/container/XIndexReplace.hpp> #include <com/sun/star/uno/Reference.h> #include <xmloff/xmlictxt.hxx> +#include "txthints.hxx" -class XMLHints_Impl; namespace com::sun::star { namespace text { class XTextRange; } namespace xml::sax { class XAttributeList; } @@ -45,7 +45,7 @@ class XMLParaContext : public SvXMLImportContext css::uno::Any m_aMarkerStyleName; bool m_bHaveAbout; sal_Int8 nOutlineLevel; - std::unique_ptr<XMLHints_Impl> m_xHints; + std::optional<XMLHints_Impl> m_oHints; // Lost outline numbering in master document (#i73509#) bool mbOutlineLevelAttrFound; bool mbOutlineContentVisible;