[pango/cache-context-metrics] context: Cache metrics for the current font
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/cache-context-metrics] context: Cache metrics for the current font
- Date: Thu, 18 Mar 2021 04:11:24 +0000 (UTC)
commit 2214326a9669af950593da08c98505c62e27974a
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 18 00:09:58 2021 -0400
context: Cache metrics for the current font
GTK calls pango_context_get_metrics() frequently to
determine character widths and alignments, and does not
expect this to involve expensive layout operations.
pango/pango-context.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
---
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 1db11a1c..ccaa1bac 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -63,6 +63,8 @@ struct _PangoContext
PangoFontMap *font_map;
+ PangoFontMetrics *metrics;
+
gboolean round_glyph_positions;
};
@@ -121,6 +123,9 @@ pango_context_finalize (GObject *object)
if (context->matrix)
pango_matrix_free (context->matrix);
+ if (context->metrics)
+ pango_font_metrics_unref (context->metrics);
+
G_OBJECT_CLASS (pango_context_parent_class)->finalize (object);
}
@@ -1783,6 +1788,11 @@ pango_context_get_metrics (PangoContext *context,
if (!language)
language = context->language;
+ if (desc == context->font_desc &&
+ language == context->language &&
+ context->metrics != NULL)
+ return pango_font_metrics_ref (context->metrics);
+
current_fonts = pango_font_map_load_fontset (context->font_map, context, desc, language);
metrics = get_base_metrics (current_fonts);
@@ -1797,6 +1807,10 @@ pango_context_get_metrics (PangoContext *context,
g_object_unref (current_fonts);
+ if (desc == context->font_desc &&
+ language == context->language)
+ context->metrics = pango_font_metrics_ref (metrics);
+
return metrics;
}
@@ -1806,6 +1820,8 @@ context_changed (PangoContext *context)
context->serial++;
if (context->serial == 0)
context->serial++;
+
+ g_clear_pointer (&context->metrics, pango_font_metrics_unref);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]