diff options
author | Noel Grandin <noel@peralex.com> | 2021-09-28 14:47:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-28 18:24:52 +0200 |
commit | b62153753a9f21afb2a49110ef0459e427b0b01a (patch) | |
tree | 223e90503ecb82657a9990ddca7103296b20648c /sw | |
parent | 082394a8ff125a7a7a009f60a0002d1d4c2ca7fb (diff) |
tdf#135683 speedup SwAttrHandler
we only care about the "highest priority" attribute, so we only
need to store a single attribute, not a whole vector worth.
Shaves 5% off the load time for me.
Change-Id: Ib7dc800db47502b33c69df0fe473a82bd8d93af5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122773
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/text/atrhndl.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/text/atrstck.cxx | 20 |
2 files changed, 10 insertions, 12 deletions
diff --git a/sw/source/core/text/atrhndl.hxx b/sw/source/core/text/atrhndl.hxx index 1033242492c3..8a3c438fd91d 100644 --- a/sw/source/core/text/atrhndl.hxx +++ b/sw/source/core/text/atrhndl.hxx @@ -38,7 +38,7 @@ extern const sal_uInt8 StackPos[]; class SwAttrHandler { private: - std::vector<const SwTextAttr*> m_aAttrStack[NUM_ATTRIBUTE_STACKS]; // stack collection + const SwTextAttr* m_aAttrStack[NUM_ATTRIBUTE_STACKS] {}; // stack collection const SfxPoolItem* m_pDefaultArray[ NUM_DEFAULT_VALUES ]; const IDocumentSettingAccess* m_pIDocumentSettingAccess; const SwViewShell* m_pShell; diff --git a/sw/source/core/text/atrstck.cxx b/sw/source/core/text/atrstck.cxx index 4cc7b501094f..794390a63ede 100644 --- a/sw/source/core/text/atrstck.cxx +++ b/sw/source/core/text/atrstck.cxx @@ -335,7 +335,7 @@ void SwAttrHandler::Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAS, void SwAttrHandler::Reset( ) { for (auto& i : m_aAttrStack) - i.clear(); + i = nullptr; } void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt ) @@ -384,7 +384,7 @@ void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt ) const SwTextAttr* SwAttrHandler::GetTop(sal_uInt16 nStack) { - return m_aAttrStack[nStack].empty() ? nullptr : m_aAttrStack[nStack].back(); + return m_aAttrStack[nStack]; } bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem ) @@ -406,21 +406,20 @@ bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem ) || ( !pTopAttr->IsPriorityAttr() && !lcl_ChgHyperLinkColor(*pTopAttr, rItem, m_pShell, nullptr))) { - m_aAttrStack[nStack].push_back(&rAttr); + m_aAttrStack[nStack] = &rAttr; return true; } - const auto it = m_aAttrStack[nStack].end() - 1; - m_aAttrStack[nStack].insert(it, &rAttr); + if (!pTopAttr) + m_aAttrStack[nStack] = &rAttr; return false; } void SwAttrHandler::RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr) { auto& rStack = m_aAttrStack[StackPos[nWhich]]; - const auto it = std::find(rStack.begin(), rStack.end(), &rAttr); - if (it != rStack.end()) - rStack.erase(it); + if (rStack == &rAttr) + rStack = nullptr; } void SwAttrHandler::PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt ) @@ -740,7 +739,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush ) // 2. top of two line stack ( or default attribute )is an // deactivated two line attribute const bool bRuby = - 0 != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size(); + nullptr != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ]; if ( bRuby ) break; @@ -764,8 +763,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush ) } case RES_CHRATR_TWO_LINES : { - bool bRuby = 0 != - m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size(); + bool bRuby = nullptr != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ]; // two line is activated, if // 1. no ruby attribute is set and |