diff --git a/common/font/glyph.cpp b/common/font/glyph.cpp index 546f041944..d1e0b49dae 100644 --- a/common/font/glyph.cpp +++ b/common/font/glyph.cpp @@ -38,8 +38,8 @@ void STROKE_GLYPH::AddPoint( const VECTOR2D& aPoint ) { if( !m_penIsDown ) { - std::vector v; - push_back( v ); + emplace_back(); + back().reserve( 16 ); // This handles all but 359 strokes (out of over 328,000) m_penIsDown = true; } @@ -49,8 +49,10 @@ void STROKE_GLYPH::AddPoint( const VECTOR2D& aPoint ) void STROKE_GLYPH::RaisePen() { +#if 0 if( m_penIsDown ) back().shrink_to_fit(); +#endif m_penIsDown = false; } @@ -58,8 +60,12 @@ void STROKE_GLYPH::RaisePen() void STROKE_GLYPH::Finalize() { - if( !empty() && !back().empty() ) + // Shrinking the strokes saves a bit less than 512K of memory. It's not worth it for the + // performance hit of doing more than 328,000 reallocs. +#if 0 +if( !empty() && !back().empty() ) back().shrink_to_fit(); +#endif } diff --git a/common/font/stroke_font.cpp b/common/font/stroke_font.cpp index bb89eb714e..ec7c1c6edb 100644 --- a/common/font/stroke_font.cpp +++ b/common/font/stroke_font.cpp @@ -108,14 +108,26 @@ void STROKE_FONT::loadNewStrokeFont( const char* const aNewStrokeFont[], int aNe for( int j = 0; j < aNewStrokeFontSize; j++ ) { - auto glyph = std::make_shared(); + std::shared_ptr glyph = std::make_shared(); + double glyphStartX = 0.0; double glyphEndX = 0.0; double glyphWidth = 0.0; + int strokes = 0; + int i = 0; - std::vector* pointList = nullptr; + while( aNewStrokeFont[j][i] ) + { - int i = 0; + if( aNewStrokeFont[j][i] == ' ' && aNewStrokeFont[j][i+1] == 'R' ) + strokes++; + + i += 2; + } + + glyph->reserve( strokes + 1 ); + + i = 0; while( aNewStrokeFont[j][i] ) { @@ -153,9 +165,6 @@ void STROKE_FONT::loadNewStrokeFont( const char* const aNewStrokeFont[], int aNe // Only shapes like j y have coordinates < 0 point.y = (double) ( coordinate[1] - 'R' + FONT_OFFSET ) * STROKE_FONT_SCALE; - if( !pointList ) - pointList = new std::vector; - glyph->AddPoint( point ); }