diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-11-10 16:49:58 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-11-17 18:10:42 +0100 |
commit | ed2c3a53853fbc4df843c10aecbfa463b6a67475 (patch) | |
tree | 2f504e2ad592211e9d4a1b66d4de9394ad98ab9e /editeng | |
parent | cc00f501b8686ae5a4f7db2a1546af9e04e0eab2 (diff) |
editeng: Avoid calling expensive getLineBreak() if possible
ImpEditEngine::ImpBreakLine: if nMinBreakPos == nMaxBreakPos just set
nBreakPos to the same value directly.
Change-Id: I4544cb6c56f68071cba739260161bb24ef5a3f7f
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/impedit3.cxx | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index f68bc5ca8422..bcbe8dcb73c0 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -1769,45 +1769,56 @@ void ImpEditEngine::ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, Te break; } } + assert(nMinBreakPos <= nMaxBreakPos); lang::Locale aLocale = GetLocale( EditPaM( pNode, nMaxBreakPos ) ); Reference < i18n::XBreakIterator > _xBI( ImplGetBreakIterator() ); - Reference< XHyphenator > xHyph; - if ( bCanHyphenate ) - xHyph = GetHyphenator(); - i18n::LineBreakHyphenationOptions aHyphOptions( xHyph, Sequence< PropertyValue >(), 1 ); - i18n::LineBreakUserOptions aUserOptions; - - const i18n::ForbiddenCharacters* pForbidden = GetForbiddenCharsTable()->GetForbiddenCharacters( LanguageTag::convertToLanguageType( aLocale ), true ); - aUserOptions.forbiddenBeginCharacters = pForbidden->beginLine; - aUserOptions.forbiddenEndCharacters = pForbidden->endLine; - aUserOptions.applyForbiddenRules = static_cast<const SfxBoolItem&>(pNode->GetContentAttribs().GetItem( EE_PARA_FORBIDDENRULES )).GetValue(); - aUserOptions.allowPunctuationOutsideMargin = static_cast<const SfxBoolItem&>(pNode->GetContentAttribs().GetItem( EE_PARA_HANGINGPUNCTUATION )).GetValue(); - aUserOptions.allowHyphenateEnglish = sal_False; - - i18n::LineBreakResults aLBR = _xBI->getLineBreak( - pNode->GetString(), nMaxBreakPos, aLocale, nMinBreakPos, aHyphOptions, aUserOptions ); - nBreakPos = aLBR.breakIndex; - - // BUG in I18N - under special condition (break behind field, #87327#) breakIndex is < nMinBreakPos - if ( nBreakPos < nMinBreakPos ) + const bool bAllowPunctuationOutsideMargin = static_cast<const SfxBoolItem&>( + pNode->GetContentAttribs().GetItem( EE_PARA_HANGINGPUNCTUATION )).GetValue(); + + if (nMinBreakPos == nMaxBreakPos) { nBreakPos = nMinBreakPos; } - else if ( ( nBreakPos > nMaxBreakPos ) && !aUserOptions.allowPunctuationOutsideMargin ) + else { - OSL_FAIL( "I18N: XBreakIterator::getLineBreak returns position > Max" ); - nBreakPos = nMaxBreakPos; - } + Reference< XHyphenator > xHyph; + if ( bCanHyphenate ) + xHyph = GetHyphenator(); + i18n::LineBreakHyphenationOptions aHyphOptions( xHyph, Sequence< PropertyValue >(), 1 ); + i18n::LineBreakUserOptions aUserOptions; + + const i18n::ForbiddenCharacters* pForbidden = GetForbiddenCharsTable()->GetForbiddenCharacters( LanguageTag::convertToLanguageType( aLocale ), true ); + aUserOptions.forbiddenBeginCharacters = pForbidden->beginLine; + aUserOptions.forbiddenEndCharacters = pForbidden->endLine; + aUserOptions.applyForbiddenRules = static_cast<const SfxBoolItem&>(pNode->GetContentAttribs().GetItem( EE_PARA_FORBIDDENRULES )).GetValue(); + aUserOptions.allowPunctuationOutsideMargin = bAllowPunctuationOutsideMargin; + aUserOptions.allowHyphenateEnglish = sal_False; + + i18n::LineBreakResults aLBR = _xBI->getLineBreak( + pNode->GetString(), nMaxBreakPos, aLocale, nMinBreakPos, aHyphOptions, aUserOptions ); + nBreakPos = aLBR.breakIndex; + + // BUG in I18N - under special condition (break behind field, #87327#) breakIndex is < nMinBreakPos + if ( nBreakPos < nMinBreakPos ) + { + nBreakPos = nMinBreakPos; + } + else if ( ( nBreakPos > nMaxBreakPos ) && !aUserOptions.allowPunctuationOutsideMargin ) + { + OSL_FAIL( "I18N: XBreakIterator::getLineBreak returns position > Max" ); + nBreakPos = nMaxBreakPos; + } - // nBreakPos can never be outside the portion, even not with hangig punctuation - if ( nBreakPos > nMaxBreakPos ) - nBreakPos = nMaxBreakPos; + // nBreakPos can never be outside the portion, even not with hangig punctuation + if ( nBreakPos > nMaxBreakPos ) + nBreakPos = nMaxBreakPos; + } // BUG in I18N - the japanese dot is in the next line! // !!! Test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - if ( (nBreakPos + ( aUserOptions.allowPunctuationOutsideMargin ? 0 : 1 ) ) <= nMaxBreakPos ) + if ( (nBreakPos + ( bAllowPunctuationOutsideMargin ? 0 : 1 ) ) <= nMaxBreakPos ) { sal_Unicode cFirstInNextLine = ( (nBreakPos+1) < pNode->Len() ) ? pNode->GetChar( nBreakPos ) : 0; if ( cFirstInNextLine == 12290 ) |