Performance optimizations for building the stroke font.

This commit is contained in:
Jeff Young 2022-01-09 14:28:07 +00:00
parent 9b569e4739
commit 7e18256386
2 changed files with 24 additions and 9 deletions

View File

@ -38,8 +38,8 @@ void STROKE_GLYPH::AddPoint( const VECTOR2D& aPoint )
{
if( !m_penIsDown )
{
std::vector<VECTOR2D> 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
}

View File

@ -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<STROKE_GLYPH>();
std::shared_ptr<STROKE_GLYPH> glyph = std::make_shared<STROKE_GLYPH>();
double glyphStartX = 0.0;
double glyphEndX = 0.0;
double glyphWidth = 0.0;
int strokes = 0;
int i = 0;
std::vector<VECTOR2D>* 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<VECTOR2D>;
glyph->AddPoint( point );
}