diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-09-06 11:01:46 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-09-06 11:10:09 +0200 |
commit | 871cc47c5ea66d1c2f1cbff5d7564202192ea84c (patch) | |
tree | 2a65fd5d221aa5cdbbf29d85b28d23ee1f1e549c /editeng | |
parent | 3bc61004287e1d1a734c6046019d605742f6c629 (diff) |
use a faster standard algorithm to workaround performance problem, fdo#68089
We have here an O(n^2) algorithm. At least using std::find_if here
improves the inner loop and fixes the problem with the bug document.
Change-Id: I88dea9434df6c669f4897927a721ad1518d7ca5e
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/impedit2.cxx | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index b9d3103d9fd2..aa8c3fdb01b2 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -1739,6 +1739,24 @@ void ImpEditEngine::InitScriptTypes( sal_Int32 nPara ) } } +namespace { + +struct FindByPos +{ + FindByPos(sal_uInt16 nPos): + mnPos(nPos) {} + + bool operator()(const ScriptTypePosInfos::value_type& rValue) + { + return rValue.nStartPos <= mnPos && rValue.nEndPos >= mnPos; + } + +private: + sal_uInt16 mnPos; +}; + +} + sal_uInt16 ImpEditEngine::GetScriptType( const EditPaM& rPaM, sal_uInt16* pEndPos ) const { sal_uInt16 nScriptType = 0; @@ -1754,16 +1772,14 @@ sal_uInt16 ImpEditEngine::GetScriptType( const EditPaM& rPaM, sal_uInt16* pEndPo ((ImpEditEngine*)this)->InitScriptTypes( nPara ); const ScriptTypePosInfos& rTypes = pParaPortion->aScriptInfos; + sal_uInt16 nPos = rPaM.GetIndex(); - for ( size_t n = 0; n < rTypes.size(); n++ ) + ScriptTypePosInfos::const_iterator itr = std::find_if(rTypes.begin(), rTypes.end(), FindByPos(nPos)); + if(itr != rTypes.end()) { - if ( ( rTypes[n].nStartPos <= nPos ) && ( rTypes[n].nEndPos >= nPos ) ) - { - nScriptType = rTypes[n].nScriptType; - if( pEndPos ) - *pEndPos = rTypes[n].nEndPos; - break; - } + nScriptType = itr->nScriptType; + if( pEndPos ) + *pEndPos = itr->nEndPos; } } return nScriptType ? nScriptType : GetI18NScriptTypeOfLanguage( GetDefaultLanguage() ); |