- // If no number of characters is given, just set something sensible to avoid reallocations.
- numberOfCharacters = static_cast<Length> ( static_cast<float>( mGlyphs.Count() ) * 1.3f );
+ // Nothing to do.
+ return;
+ }
+
+ // Get the total number of characters.
+ const Length totalNumberOfCharacters = ( 0u == mGlyphsToCharacters.Count() ) ? 0u : *( mGlyphsToCharacters.End() - 1u ) + *( mCharactersPerGlyph.End() - 1u ); // Index to the first character + the number of characters that form the last glyph.
+
+ // Whether the current buffer is being updated or is set from scratch.
+ const bool updateCurrentBuffer = numberOfCharacters < totalNumberOfCharacters;
+
+ Vector<Length> newGlyphsPerCharacter;
+ Length* glyphsPerCharacterBuffer = NULL;
+
+ // 1) Reserve some space for the glyphs per character to avoid reallocations.
+ if( updateCurrentBuffer )
+ {
+ newGlyphsPerCharacter.Resize( numberOfCharacters );
+ glyphsPerCharacterBuffer = newGlyphsPerCharacter.Begin();
+ }
+ else
+ {
+ mGlyphsPerCharacter.Resize( numberOfCharacters );
+ glyphsPerCharacterBuffer = mGlyphsPerCharacter.Begin() + startIndex;