From 50723d07a6fb79c7825c85e1d027139b5f1ef0cf Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 18 Oct 2019 21:48:58 -0700 Subject: [PATCH] GAL: Use vector for stroke elements deque structures have higher overhead than vectors. Not usually problematic, but with hundreds of thousands of characters each with only a few strokes, the overhead becomes dominant. (cherry picked from commit 60846143714de3500347cd0d8cb3176679b409d7) --- common/gal/stroke_font.cpp | 21 +++++++++------------ include/gal/stroke_font.h | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/common/gal/stroke_font.cpp b/common/gal/stroke_font.cpp index ec7f64ea78..a562205146 100644 --- a/common/gal/stroke_font.cpp +++ b/common/gal/stroke_font.cpp @@ -60,7 +60,7 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe double glyphEndX = 0.0; VECTOR2D glyphBoundingX; - std::deque* pointList = nullptr; + std::vector* pointList = nullptr; int i = 0; @@ -105,7 +105,7 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe if( !pointList ) { - glyph.emplace_back( std::deque() ); + glyph.emplace_back( std::vector() ); pointList = &glyph.back(); } @@ -140,17 +140,16 @@ BOX2D STROKE_FONT::computeBoundingBox( const GLYPH& aGLYPH, const VECTOR2D& aGLY { BOX2D boundingBox; - std::deque boundingPoints; + std::vector boundingPoints; boundingPoints.emplace_back( VECTOR2D( aGLYPHBoundingX.x, 0 ) ); boundingPoints.emplace_back( VECTOR2D( aGLYPHBoundingX.y, 0 ) ); - for( GLYPH::const_iterator pointListIt = aGLYPH.begin(); pointListIt != aGLYPH.end(); ++pointListIt ) + for( const auto& pointList : aGLYPH ) { - for( std::deque::const_iterator pointIt = pointListIt->begin(); - pointIt != pointListIt->end(); ++pointIt ) + for( const auto& pt : pointList ) { - boundingPoints.emplace_back( VECTOR2D( aGLYPHBoundingX.x, pointIt->y ) ); + boundingPoints.emplace_back( aGLYPHBoundingX.x, pt.y ); } } @@ -341,15 +340,13 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText ) last_had_overbar = false; } - for( GLYPH::iterator pointListIt = glyph.begin(); pointListIt != glyph.end(); - ++pointListIt ) + for( const auto& pointList : glyph ) { std::deque pointListScaled; - for( std::deque::iterator pointIt = pointListIt->begin(); - pointIt != pointListIt->end(); ++pointIt ) + for( const auto& pt : pointList ) { - VECTOR2D pointPos( pointIt->x * glyphSize.x + xOffset, pointIt->y * glyphSize.y ); + VECTOR2D pointPos( pt.x * glyphSize.x + xOffset, pt.y * glyphSize.y ); if( m_gal->IsFontItalic() ) { diff --git a/include/gal/stroke_font.h b/include/gal/stroke_font.h index b1a6680bf8..879dcd4896 100644 --- a/include/gal/stroke_font.h +++ b/include/gal/stroke_font.h @@ -42,7 +42,7 @@ namespace KIGFX { class GAL; -typedef std::deque< std::deque > GLYPH; +typedef std::vector> GLYPH; typedef std::vector GLYPH_LIST; /**