summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-11-12 21:55:33 +0100
committerMichael Stahl <mstahl@redhat.com>2015-11-13 11:03:07 +0100
commit0ab6b1fc6e84b4f5f3a9c0b93b999aa320a70a0e (patch)
tree2e79d032317b586ef2b5c4e51d4d0461e6213d9b /sw
parent655248f1b504af18782caaa5b903623145ab80e5 (diff)
sw: shove 2 global variables into SwHyphIter
Change-Id: I0cb6112b0353a5fd0b4dd571d65f2d656e39ba74
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/splargs.hxx13
-rw-r--r--sw/source/core/edit/edlingu.cxx32
-rw-r--r--sw/source/core/txtnode/txtedt.cxx12
3 files changed, 41 insertions, 16 deletions
diff --git a/sw/inc/splargs.hxx b/sw/inc/splargs.hxx
index dd1e736fe954..33fe9424fed5 100644
--- a/sw/inc/splargs.hxx
+++ b/sw/inc/splargs.hxx
@@ -22,12 +22,15 @@
#include <i18nlangtag/lang.h>
#include <tools/solar.h>
#include <tools/gen.hxx>
-#include <limits.h>
#include <com/sun/star/linguistic2/XSpellAlternatives.hpp>
#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
#include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
+#include <functional>
+#include <limits.h>
+
+class SwTextFrm;
class SwTextNode;
class SwIndex;
namespace vcl { class Font; }
@@ -152,6 +155,14 @@ public:
}
};
+
+namespace sw {
+
+SwTextFrm *
+SwHyphIterCacheLastTxtFrm(SwTextNode *, std::function<SwTextFrm * ()>);
+
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 92a2d99bfc8b..49d32024b346 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -155,11 +155,16 @@ public:
class SwHyphIter : public SwLinguIter
{
+ // With that we save a GetFrm() in Hyphenate //TODO: does it actually matter?
+ const SwTextNode *m_pLastNode;
+ SwTextFrm *m_pLastFrm;
+ friend SwTextFrm * sw::SwHyphIterCacheLastTxtFrm(SwTextNode *, std::function<SwTextFrm * ()>);
+
bool bOldIdle;
static void DelSoftHyph( SwPaM &rPam );
public:
- SwHyphIter() : bOldIdle(false) {}
+ SwHyphIter() : m_pLastNode(nullptr), m_pLastFrm(nullptr), bOldIdle(false) {}
void Start( SwEditShell *pSh, SwDocPositions eStart, SwDocPositions eEnd );
void End();
@@ -177,11 +182,6 @@ static SwSpellIter* g_pSpellIter = nullptr;
static SwConvIter* g_pConvIter = nullptr;
static SwHyphIter* g_pHyphIter = nullptr;
-// With that we save a GetFrm() in Hyphenate.
-// Caution: There are external declaration to these pointers in txtedt.cxx!
-const SwTextNode *pLinguNode;
- SwTextFrm *pLinguFrm;
-
SwLinguIter::SwLinguIter()
: pSh(nullptr)
, pStart(nullptr)
@@ -249,9 +249,6 @@ void SwLinguIter::_Start( SwEditShell *pShell, SwDocPositions eStart,
}
pCrsr->SetMark();
-
- pLinguFrm = nullptr;
- pLinguNode = nullptr;
}
void SwLinguIter::_End(bool bRestoreSelection)
@@ -572,6 +569,23 @@ void SwHyphIter::InsertSoftHyph( const sal_Int32 nHyphPos )
pCrsr->SetMark();
}
+namespace sw {
+
+SwTextFrm *
+SwHyphIterCacheLastTxtFrm(SwTextNode *const pNode,
+ std::function<SwTextFrm * ()> const create)
+{
+ assert(g_pHyphIter);
+ if (pNode != g_pHyphIter->m_pLastNode || !g_pHyphIter->m_pLastFrm)
+ {
+ g_pHyphIter->m_pLastNode = pNode;
+ g_pHyphIter->m_pLastFrm = create();
+ }
+ return g_pHyphIter->m_pLastFrm;
+}
+
+}
+
bool SwEditShell::HasLastSentenceGotGrammarChecked()
{
bool bTextWasGrammarChecked = false;
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 342538e18b99..e8e060f1b84a 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -1618,12 +1618,12 @@ bool SwTextNode::Hyphenate( SwInterHyphInfo &rHyphInf )
return false;
}
- if( pLinguNode != this )
- {
- pLinguNode = this;
- pLinguFrm = static_cast<SwTextFrm*>(getLayoutFrm( GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(), rHyphInf.GetCrsrPos() ));
- }
- SwTextFrm *pFrm = pLinguFrm;
+ SwTextFrm *pFrm = ::sw::SwHyphIterCacheLastTxtFrm(this,
+ [&rHyphInf, this]() {
+ return static_cast<SwTextFrm*>(this->getLayoutFrm(
+ this->GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
+ rHyphInf.GetCrsrPos()));
+ });
if( pFrm )
pFrm = &(pFrm->GetFrmAtOfst( rHyphInf.nStart ));
else