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
This commit is contained in:
parent
3bc6100428
commit
871cc47c5e
@ -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 ImpEditEngine::GetScriptType( const EditPaM& rPaM, sal_uInt16* pEndPos ) const
|
||||||
{
|
{
|
||||||
sal_uInt16 nScriptType = 0;
|
sal_uInt16 nScriptType = 0;
|
||||||
@ -1754,16 +1772,14 @@ sal_uInt16 ImpEditEngine::GetScriptType( const EditPaM& rPaM, sal_uInt16* pEndPo
|
|||||||
((ImpEditEngine*)this)->InitScriptTypes( nPara );
|
((ImpEditEngine*)this)->InitScriptTypes( nPara );
|
||||||
|
|
||||||
const ScriptTypePosInfos& rTypes = pParaPortion->aScriptInfos;
|
const ScriptTypePosInfos& rTypes = pParaPortion->aScriptInfos;
|
||||||
|
|
||||||
sal_uInt16 nPos = rPaM.GetIndex();
|
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 = itr->nScriptType;
|
||||||
{
|
if( pEndPos )
|
||||||
nScriptType = rTypes[n].nScriptType;
|
*pEndPos = itr->nEndPos;
|
||||||
if( pEndPos )
|
|
||||||
*pEndPos = rTypes[n].nEndPos;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nScriptType ? nScriptType : GetI18NScriptTypeOfLanguage( GetDefaultLanguage() );
|
return nScriptType ? nScriptType : GetI18NScriptTypeOfLanguage( GetDefaultLanguage() );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user