Codechange: Store text layout runs directly as values in a std::vector instead of heap allocated.
This reduces memory allocations and heap fragmentation.
This commit is contained in:
16
src/gfx.cpp
16
src/gfx.cpp
@@ -376,7 +376,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left,
|
||||
* another size would be chosen it won't have truncated too little for
|
||||
* the truncation dots.
|
||||
*/
|
||||
FontCache *fc = ((const Font*)line->GetVisualRun(0)->GetFont())->fc;
|
||||
FontCache *fc = ((const Font*)line->GetVisualRun(0).GetFont())->fc;
|
||||
GlyphID dot_glyph = fc->MapCharToGlyph('.');
|
||||
dot_width = fc->GetGlyphWidth(dot_glyph);
|
||||
dot_sprite = fc->GetGlyph(dot_glyph);
|
||||
@@ -422,8 +422,8 @@ static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left,
|
||||
TextColour colour = TC_BLACK;
|
||||
bool draw_shadow = false;
|
||||
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
|
||||
const Font *f = (const Font*)run->GetFont();
|
||||
const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index);
|
||||
const Font *f = (const Font*)run.GetFont();
|
||||
|
||||
FontCache *fc = f->fc;
|
||||
colour = f->colour;
|
||||
@@ -435,15 +435,15 @@ static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left,
|
||||
|
||||
draw_shadow = fc->GetDrawGlyphShadow() && (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
|
||||
|
||||
for (int i = 0; i < run->GetGlyphCount(); i++) {
|
||||
GlyphID glyph = run->GetGlyphs()[i];
|
||||
for (int i = 0; i < run.GetGlyphCount(); i++) {
|
||||
GlyphID glyph = run.GetGlyphs()[i];
|
||||
|
||||
/* Not a valid glyph (empty) */
|
||||
if (glyph == 0xFFFF) continue;
|
||||
|
||||
int begin_x = (int)run->GetPositions()[i * 2] + left - offset_x;
|
||||
int end_x = (int)run->GetPositions()[i * 2 + 2] + left - offset_x - 1;
|
||||
int top = (int)run->GetPositions()[i * 2 + 1] + y;
|
||||
int begin_x = (int)run.GetPositions()[i * 2] + left - offset_x;
|
||||
int end_x = (int)run.GetPositions()[i * 2 + 2] + left - offset_x - 1;
|
||||
int top = (int)run.GetPositions()[i * 2 + 1] + y;
|
||||
|
||||
/* Truncated away. */
|
||||
if (truncation && (begin_x < min_x || end_x > max_x)) continue;
|
||||
|
Reference in New Issue
Block a user