[Libreoffice-commits] core.git: editeng/source include/editeng sw/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sun Apr 12 12:56:14 UTC 2020
editeng/source/editeng/impedit3.cxx | 2 +-
editeng/source/misc/txtrange.cxx | 28 ++++++++++++++--------------
include/editeng/txtrange.hxx | 24 +++++++++++-------------
sw/source/core/text/txtfly.cxx | 2 +-
4 files changed, 27 insertions(+), 29 deletions(-)
New commits:
commit f6a1859704bf7f29d6cb55e37ac82affba9da1e5
Author: Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Apr 12 13:22:20 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Apr 12 14:55:42 2020 +0200
small cleanups in TextRanger
- no need for mpPolyPolygon to be allocated out of line.
- expand out LongDqPtr typedef, not much longer and makes the code
easier to read
- allocate mpBound inline using std::optional
- rename RangeCache to RangeCacheItem
Change-Id: I55032a31eaefa844059edb5f0ee599f1b813ac80
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92079
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 05ab3ccf6823..b9a33ceec64d 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -809,7 +809,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
long nTmpWidth = 0;
long nXWidth = nMaxLineWidth;
- LongDqPtr pTextRanges = nullptr;
+ std::deque<long>* pTextRanges = nullptr;
long nTextExtraYOffset = 0;
long nTextXOffset = 0;
long nTextLineHeight = 0;
diff --git a/editeng/source/misc/txtrange.cxx b/editeng/source/misc/txtrange.cxx
index cc4417498721..42d674c42780 100644
--- a/editeng/source/misc/txtrange.cxx
+++ b/editeng/source/misc/txtrange.cxx
@@ -31,6 +31,7 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
const basegfx::B2DPolyPolygon* pLinePolyPolygon,
sal_uInt16 nCacheSz, sal_uInt16 nLft, sal_uInt16 nRght,
bool bSimpl, bool bInnr, bool bVert ) :
+ maPolyPolygon( rPolyPolygon.count() ),
nCacheSize( nCacheSz ),
nRight( nRght ),
nLeft( nLft ),
@@ -42,13 +43,12 @@ TextRanger::TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
bVertical( bVert )
{
sal_uInt32 nCount(rPolyPolygon.count());
- mpPolyPolygon.reset( new tools::PolyPolygon( static_cast<sal_uInt16>(nCount) ) );
for(sal_uInt32 i(0); i < nCount; i++)
{
const basegfx::B2DPolygon aCandidate(rPolyPolygon.getB2DPolygon(i).getDefaultAdaptiveSubdivision());
nPointCount += aCandidate.count();
- mpPolyPolygon->Insert( tools::Polygon(aCandidate), static_cast<sal_uInt16>(i) );
+ maPolyPolygon.Insert( tools::Polygon(aCandidate), static_cast<sal_uInt16>(i) );
}
if( pLinePolyPolygon )
@@ -93,7 +93,7 @@ namespace {
class SvxBoundArgs
{
std::vector<bool> aBoolArr;
- LongDqPtr pLongArr;
+ std::deque<long>* pLongArr;
TextRanger *pTextRanger;
long nMin;
long nMax;
@@ -126,7 +126,7 @@ class SvxBoundArgs
long A( const Point& rP ) const { return bRotate ? rP.Y() : rP.X(); }
long B( const Point& rP ) const { return bRotate ? rP.X() : rP.Y(); }
public:
- SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong, const Range& rRange );
+ SvxBoundArgs( TextRanger* pRanger, std::deque<long>* pLong, const Range& rRange );
void NotePoint( const long nA ) { NoteMargin( nA - nStart, nA + nEnd ); }
void NoteMargin( const long nL, const long nR )
{ if( nMin > nL ) nMin = nL; if( nMax < nR ) nMax = nR; }
@@ -142,7 +142,7 @@ public:
}
-SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, LongDqPtr pLong,
+SvxBoundArgs::SvxBoundArgs( TextRanger* pRanger, std::deque<long>* pLong,
const Range& rRange )
: pLongArr(pLong)
, pTextRanger(pRanger)
@@ -489,7 +489,7 @@ void SvxBoundArgs::Concat( const tools::PolyPolygon* pPoly )
{
SetConcat( true );
DBG_ASSERT( pPoly, "Nothing to do?" );
- LongDqPtr pOld = pLongArr;
+ std::deque<long>* pOld = pLongArr;
pLongArr = new std::deque<long>;
aBoolArr.clear();
bInner = false;
@@ -631,7 +631,7 @@ void SvxBoundArgs::NoteUpLow( long nA, const sal_uInt8 nArea )
}
}
-LongDqPtr TextRanger::GetTextRanges( const Range& rRange )
+std::deque<long>* TextRanger::GetTextRanges( const Range& rRange )
{
DBG_ASSERT( rRange.Min() || rRange.Max(), "Zero-Range not allowed, Bye Bye" );
//Can we find the result we need in the cache?
@@ -641,23 +641,23 @@ LongDqPtr TextRanger::GetTextRanges( const Range& rRange )
return &(elem.results);
}
//Calculate a new result
- RangeCache rngCache(rRange);
+ RangeCacheItem rngCache(rRange);
SvxBoundArgs aArg( this, &(rngCache.results), rRange );
- aArg.Calc( *mpPolyPolygon );
+ aArg.Calc( maPolyPolygon );
if( mpLinePolyPolygon )
aArg.Concat( mpLinePolyPolygon.get() );
//Add new result to the cache
- mRangeCache.push_back(rngCache);
+ mRangeCache.push_back(std::move(rngCache));
if (mRangeCache.size() > nCacheSize)
mRangeCache.pop_front();
return &(mRangeCache.back().results);
}
-const tools::Rectangle& TextRanger::GetBoundRect_()
+const tools::Rectangle& TextRanger::GetBoundRect_() const
{
- DBG_ASSERT( nullptr == pBound, "Don't call twice." );
- pBound.reset( new tools::Rectangle( mpPolyPolygon->GetBoundRect() ) );
- return *pBound;
+ DBG_ASSERT( !mxBound, "Don't call twice." );
+ mxBound = maPolyPolygon.GetBoundRect();
+ return *mxBound;
}
diff --git a/include/editeng/txtrange.hxx b/include/editeng/txtrange.hxx
index c26790115ea6..1898a364966b 100644
--- a/include/editeng/txtrange.hxx
+++ b/include/editeng/txtrange.hxx
@@ -22,30 +22,28 @@
#include <editeng/editengdllapi.h>
#include <tools/gen.hxx>
+#include <tools/poly.hxx>
#include <deque>
#include <memory>
-
-namespace tools { class PolyPolygon; }
+#include <optional>
namespace basegfx {
class B2DPolyPolygon;
}
-typedef std::deque<long>* LongDqPtr;
-
class EDITENG_DLLPUBLIC TextRanger
{
//! The RangeCache class is used to cache the result of a single range calculation.
- struct RangeCache
+ struct RangeCacheItem
{
Range range; //!< Range for which we calculated results.
std::deque<long> results; //!< Calculated results for the range.
- RangeCache(const Range& rng) : range(rng) {};
+ RangeCacheItem(const Range& rng) : range(rng) {};
};
- std::deque<RangeCache> mRangeCache; //!< Cached range calculations.
- std::unique_ptr<tools::PolyPolygon> mpPolyPolygon; // Surface polygon
+ std::deque<RangeCacheItem> mRangeCache; //!< Cached range calculations.
+ tools::PolyPolygon maPolyPolygon; // Surface polygon
std::unique_ptr<tools::PolyPolygon> mpLinePolyPolygon; // Line polygon
- std::unique_ptr<tools::Rectangle> pBound; // Comprehensive rectangle
+ mutable std::optional<tools::Rectangle> mxBound; // Comprehensive rectangle
sal_uInt16 nCacheSize; // Cache-Size
sal_uInt16 nRight; // Distance Contour-Text
sal_uInt16 nLeft; // Distance Text-Contour
@@ -58,14 +56,14 @@ class EDITENG_DLLPUBLIC TextRanger
bool bVertical :1;// for vertical writing mode
TextRanger( const TextRanger& ) = delete;
- const tools::Rectangle& GetBoundRect_();
+ const tools::Rectangle& GetBoundRect_() const;
public:
TextRanger( const basegfx::B2DPolyPolygon& rPolyPolygon,
const basegfx::B2DPolyPolygon* pLinePolyPolygon,
sal_uInt16 nCacheSize, sal_uInt16 nLeft, sal_uInt16 nRight,
bool bSimple, bool bInner, bool bVert = false );
~TextRanger();
- LongDqPtr GetTextRanges( const Range& rRange );
+ std::deque<long>* GetTextRanges( const Range& rRange );
sal_uInt16 GetRight() const { return nRight; }
sal_uInt16 GetLeft() const { return nLeft; }
sal_uInt16 GetUpper() const { return nUpper; }
@@ -74,8 +72,8 @@ public:
bool IsSimple() const { return bSimple; }
bool IsInner() const { return bInner; }
bool IsVertical() const { return bVertical; }
- const tools::Rectangle& GetBoundRect()
- { return pBound ? const_cast< const tools::Rectangle& >(*pBound) : GetBoundRect_(); }
+ const tools::Rectangle& GetBoundRect() const
+ { return mxBound ? const_cast< const tools::Rectangle& >(*mxBound) : GetBoundRect_(); }
void SetUpper( sal_uInt16 nNew ){ nUpper = nNew; }
void SetLower( sal_uInt16 nNew ){ nLower = nNew; }
void SetVertical( bool bNew );
diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx
index ac0892f81bd3..a4d7b9c9d8d3 100644
--- a/sw/source/core/text/txtfly.cxx
+++ b/sw/source/core/text/txtfly.cxx
@@ -272,7 +272,7 @@ SwRect SwContourCache::ContourRect( const SwFormat* pFormat,
Range aRange( std::min( nTmpTop, nTmpBottom ), std::max( nTmpTop, nTmpBottom ) );
- LongDqPtr pTmp = mvItems[0].mxTextRanger->GetTextRanges( aRange );
+ std::deque<long>* pTmp = mvItems[0].mxTextRanger->GetTextRanges( aRange );
const size_t nCount = pTmp->size();
if( 0 != nCount )
More information about the Libreoffice-commits
mailing list