From 0254870fe834465c58f5a7d0b39fa32ffe88ad8d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 1 Dec 2021 23:46:04 -0500 Subject: layout: Small optimization Don't calculate line width the hard way when we can do it much easier. --- pango/pango-layout.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'pango/pango-layout.c') diff --git a/pango/pango-layout.c b/pango/pango-layout.c index a9d07940..6bdf5b43 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -3269,6 +3269,7 @@ pango_layout_line_leaked (PangoLayoutLine *line) static void shape_tab (PangoLayoutLine *line, LastTabState *tab_state, + int current_width, PangoItem *item, PangoGlyphString *glyphs); @@ -3456,27 +3457,6 @@ get_tab_pos (PangoLayoutLine *line, *tab_pos -= offset; } -static int -line_width (PangoLayoutLine *line) -{ - GSList *l; - int i; - int width = 0; - - /* Compute the width of the line currently - inefficient, but easier - * than keeping the current width of the line up to date everywhere - */ - for (l = line->runs; l; l = l->next) - { - PangoLayoutRun *run = l->data; - - for (i = 0; i < run->glyphs->num_glyphs; i++) - width += run->glyphs->glyphs[i].geometry.width; - } - - return width; -} - static gboolean showing_space (const PangoAnalysis *analysis) { @@ -3513,17 +3493,15 @@ struct _LastTabState { static void shape_tab (PangoLayoutLine *line, LastTabState *tab_state, + int current_width, PangoItem *item, PangoGlyphString *glyphs) { int i, space_width; - int current_width; int tab_pos; PangoTabAlign tab_align; gunichar tab_decimal; - current_width = line_width (line); - pango_glyph_string_set_size (glyphs, 1); if (showing_space (&item->analysis)) @@ -3707,7 +3685,7 @@ shape_run (PangoLayoutLine *line, PangoGlyphString *glyphs = pango_glyph_string_new (); if (layout->text[item->offset] == '\t') - shape_tab (line, &state->last_tab, item, glyphs); + shape_tab (line, &state->last_tab, state->line_width - state->remaining_width, item, glyphs); else { PangoShapeFlags shape_flags = PANGO_SHAPE_NONE; -- cgit v1.2.1