[pango] layout/renderer: Don't heap-allocate short lived layout iterators
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] layout/renderer: Don't heap-allocate short lived layout iterators
- Date: Fri, 27 Oct 2017 21:17:33 +0000 (UTC)
commit 1599288b4f5394a314bfadae5af56d9b60150562
Author: Timm Bäder <mail baedert org>
Date: Sat Oct 7 18:22:24 2017 +0200
layout/renderer: Don't heap-allocate short lived layout iterators
Use the new _pango_layout_get_iter and _pango_layout_iter_destroy
instead.
https://bugzilla.gnome.org/show_bug.cgi?id=788643
pango/pango-layout.c | 57 ++++++++++++++++++++++++-----------------------
pango/pango-renderer.c | 15 ++++++------
2 files changed, 37 insertions(+), 35 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 3c817b6..1e123ef 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -1682,31 +1682,31 @@ pango_layout_index_to_line_and_extents (PangoLayout *layout,
int index,
PangoRectangle *line_rect)
{
- PangoLayoutIter *iter;
+ PangoLayoutIter iter;
PangoLayoutLine *line = NULL;
- iter = pango_layout_get_iter (layout);
+ _pango_layout_get_iter (layout, &iter);
- if (!ITER_IS_INVALID (iter))
+ if (!ITER_IS_INVALID (&iter))
while (TRUE)
{
- PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (iter);
+ PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (&iter);
if (tmp_line->start_index > index)
break; /* index was in paragraph delimiters */
line = tmp_line;
- pango_layout_iter_get_line_extents (iter, NULL, line_rect);
+ pango_layout_iter_get_line_extents (&iter, NULL, line_rect);
if (line->start_index + line->length > index)
break;
- if (!pango_layout_iter_next_line (iter))
+ if (!pango_layout_iter_next_line (&iter))
break; /* Use end of last line */
}
- pango_layout_iter_free (iter);
+ _pango_layout_iter_destroy (&iter);
return line;
}
@@ -1983,7 +1983,7 @@ pango_layout_xy_to_index (PangoLayout *layout,
int *index,
gint *trailing)
{
- PangoLayoutIter *iter;
+ PangoLayoutIter iter;
PangoLayoutLine *prev_line = NULL;
PangoLayoutLine *found = NULL;
int found_line_x = 0;
@@ -1994,15 +1994,15 @@ pango_layout_xy_to_index (PangoLayout *layout,
g_return_val_if_fail (PANGO_IS_LAYOUT (layout), FALSE);
- iter = pango_layout_get_iter (layout);
+ _pango_layout_get_iter (layout, &iter);
do
{
PangoRectangle line_logical;
int first_y, last_y;
- pango_layout_iter_get_line_extents (iter, NULL, &line_logical);
- pango_layout_iter_get_line_yrange (iter, &first_y, &last_y);
+ pango_layout_iter_get_line_extents (&iter, NULL, &line_logical);
+ pango_layout_iter_get_line_yrange (&iter, &first_y, &last_y);
if (y < first_y)
{
@@ -2016,27 +2016,27 @@ pango_layout_xy_to_index (PangoLayout *layout,
if (prev_line == NULL)
outside = TRUE; /* off the top */
- found = _pango_layout_iter_get_line (iter);
+ found = _pango_layout_iter_get_line (&iter);
found_line_x = x - line_logical.x;
}
}
else if (y >= first_y &&
y < last_y)
{
- found = _pango_layout_iter_get_line (iter);
+ found = _pango_layout_iter_get_line (&iter);
found_line_x = x - line_logical.x;
}
- prev_line = _pango_layout_iter_get_line (iter);
+ prev_line = _pango_layout_iter_get_line (&iter);
prev_last = last_y;
prev_line_x = x - line_logical.x;
if (found != NULL)
break;
}
- while (pango_layout_iter_next_line (iter));
+ while (pango_layout_iter_next_line (&iter));
- pango_layout_iter_free (iter);
+ _pango_layout_iter_destroy (&iter);
if (found == NULL)
{
@@ -2076,7 +2076,7 @@ pango_layout_index_to_pos (PangoLayout *layout,
PangoRectangle *pos)
{
PangoRectangle logical_rect;
- PangoLayoutIter *iter;
+ PangoLayoutIter iter;
PangoLayoutLine *layout_line = NULL;
int x_pos;
@@ -2084,20 +2084,20 @@ pango_layout_index_to_pos (PangoLayout *layout,
g_return_if_fail (index >= 0);
g_return_if_fail (pos != NULL);
- iter = pango_layout_get_iter (layout);
+ _pango_layout_get_iter (layout, &iter);
- if (!ITER_IS_INVALID (iter))
+ if (!ITER_IS_INVALID (&iter))
{
while (TRUE)
{
- PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (iter);
+ PangoLayoutLine *tmp_line = _pango_layout_iter_get_line (&iter);
if (tmp_line->start_index > index)
{
- /* index is in the paragraph delimiters, move to
+ /* index is in the paragraph delim&iters, move to
* end of previous line
*
- * This shouldn’t occur in the first loop iteration as the first
+ * This shouldn’t occur in the first loop &iteration as the first
* line’s start_index should always be 0.
*/
g_assert (layout_line != NULL);
@@ -2107,12 +2107,12 @@ pango_layout_index_to_pos (PangoLayout *layout,
layout_line = tmp_line;
- pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
+ pango_layout_iter_get_line_extents (&iter, NULL, &logical_rect);
if (layout_line->start_index + layout_line->length > index)
break;
- if (!pango_layout_iter_next_line (iter))
+ if (!pango_layout_iter_next_line (&iter))
{
index = layout_line->start_index + layout_line->length;
break;
@@ -2134,7 +2134,7 @@ pango_layout_index_to_pos (PangoLayout *layout,
pos->width = 0;
}
- pango_layout_iter_free (iter);
+ _pango_layout_iter_destroy (&iter);
}
static void
@@ -2835,11 +2835,12 @@ int
pango_layout_get_baseline (PangoLayout *layout)
{
int baseline;
+ PangoLayoutIter iter;
/* XXX this is so inefficient */
- PangoLayoutIter *iter = pango_layout_get_iter (layout);
- baseline = pango_layout_iter_get_baseline (iter);
- pango_layout_iter_free (iter);
+ _pango_layout_get_iter (layout, &iter);
+ baseline = pango_layout_iter_get_baseline (&iter);
+ _pango_layout_iter_destroy (&iter);
return baseline;
}
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index 01b9615..f82c4e4 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -24,6 +24,7 @@
#include "pango-renderer.h"
#include "pango-impl-utils.h"
+#include "pango-layout-private.h"
#define N_RENDER_PARTS 4
@@ -162,7 +163,7 @@ pango_renderer_draw_layout (PangoRenderer *renderer,
int x,
int y)
{
- PangoLayoutIter *iter;
+ PangoLayoutIter iter;
g_return_if_fail (PANGO_IS_RENDERER (renderer));
g_return_if_fail (PANGO_IS_LAYOUT (layout));
@@ -179,7 +180,7 @@ pango_renderer_draw_layout (PangoRenderer *renderer,
pango_renderer_activate (renderer);
- iter = pango_layout_get_iter (layout);
+ _pango_layout_get_iter (layout, &iter);
do
{
@@ -187,19 +188,19 @@ pango_renderer_draw_layout (PangoRenderer *renderer,
PangoLayoutLine *line;
int baseline;
- line = pango_layout_iter_get_line_readonly (iter);
+ line = pango_layout_iter_get_line_readonly (&iter);
- pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
- baseline = pango_layout_iter_get_baseline (iter);
+ pango_layout_iter_get_line_extents (&iter, NULL, &logical_rect);
+ baseline = pango_layout_iter_get_baseline (&iter);
pango_renderer_draw_layout_line (renderer,
line,
x + logical_rect.x,
y + baseline);
}
- while (pango_layout_iter_next_line (iter));
+ while (pango_layout_iter_next_line (&iter));
- pango_layout_iter_free (iter);
+ _pango_layout_iter_destroy (&iter);
pango_renderer_deactivate (renderer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]