summaryrefslogtreecommitdiff
path: root/src/gfx.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-04-02 21:30:53 +0200
committerMichael Lutz <michi@icosahedron.de>2019-04-09 22:45:15 +0200
commit329bb526134aca214a914f25006c805de78ec851 (patch)
tree00763488d458fee57ce8ba94e32ae53899367d21 /src/gfx.cpp
parent9325d63d8e55758a953f535c5f90534ab9bc01e3 (diff)
downloadopenttd-329bb526134aca214a914f25006c805de78ec851.tar.xz
Codechange: Store text layout runs directly as values in a std::vector instead of heap allocated.
This reduces memory allocations and heap fragmentation.
Diffstat (limited to 'src/gfx.cpp')
-rw-r--r--src/gfx.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index f1b91c16e..7c90285ba 100644
--- a/src/gfx.cpp
+++ b/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;