[pango/wip/baedert/for-master2: 7/17] Allocate internal PangoAttrLists on the stack
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/wip/baedert/for-master2: 7/17] Allocate internal PangoAttrLists on the stack
- Date: Mon, 8 Jun 2020 17:21:41 +0000 (UTC)
commit c802c85d0ed07cc1dae5db8f1991d82ec45bf1bd
Author: Timm Bäder <mail baedert org>
Date: Wed Apr 15 15:37:38 2020 +0200
Allocate internal PangoAttrLists on the stack
pango/break.c | 21 +++++++++--------
pango/ellipsize.c | 15 +++++++-----
pango/pango-attributes-private.h | 9 ++++++++
pango/pango-attributes.c | 50 ++++++++++++++++++++++------------------
pango/pango-layout.c | 22 +++++++++---------
5 files changed, 67 insertions(+), 50 deletions(-)
---
diff --git a/pango/break.c b/pango/break.c
index 875d776c..432ff493 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -24,6 +24,7 @@
#include "pango-break.h"
#include "pango-script-private.h"
#include "pango-emoji-private.h"
+#include "pango-attributes-private.h"
#include "pango-break-table.h"
#include "pango-impl-utils.h"
#include <string.h>
@@ -1905,31 +1906,31 @@ break_attrs (const char *text,
PangoLogAttr *log_attrs,
int log_attrs_len)
{
- PangoAttrList *list;
- PangoAttrIterator *iter;
+ PangoAttrList list;
+ PangoAttrIterator iter;
GSList *l;
- list = pango_attr_list_new ();
+ _pango_attr_list_init (&list);
for (l = attributes; l; l = l->next)
{
PangoAttribute *attr = l->data;
if (attr->klass->type == PANGO_ATTR_ALLOW_BREAKS)
- pango_attr_list_insert (list, pango_attribute_copy (attr));
+ pango_attr_list_insert (&list, pango_attribute_copy (attr));
}
- iter = pango_attr_list_get_iterator (list);
+ _pango_attr_list_get_iterator (&list, &iter);
do {
PangoAttribute *attr;
- attr = pango_attr_iterator_get (iter, PANGO_ATTR_ALLOW_BREAKS);
+ attr = pango_attr_iterator_get (&iter, PANGO_ATTR_ALLOW_BREAKS);
if (attr && ((PangoAttrInt*)attr)->value == 0)
{
int start, end;
int start_pos, end_pos;
int pos;
- pango_attr_iterator_range (iter, &start, &end);
+ pango_attr_iterator_range (&iter, &start, &end);
if (start < offset)
start_pos = 0;
else
@@ -1946,10 +1947,10 @@ break_attrs (const char *text,
log_attrs[pos].is_char_break = FALSE;
}
}
- } while (pango_attr_iterator_next (iter));
+ } while (pango_attr_iterator_next (&iter));
- pango_attr_iterator_destroy (iter);
- pango_attr_list_unref (list);
+ _pango_attr_iterator_destroy (&iter);
+ _pango_attr_list_destroy (&list);
return TRUE;
}
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index 4b27025e..4eb98a1a 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -25,6 +25,7 @@
#include "pango-glyph-item.h"
#include "pango-layout-private.h"
#include "pango-font-private.h"
+#include "pango-attributes-private.h"
#include "pango-impl-utils.h"
typedef struct _EllipsizeState EllipsizeState;
@@ -299,7 +300,7 @@ itemize_text (EllipsizeState *state,
static void
shape_ellipsis (EllipsizeState *state)
{
- PangoAttrList *attrs = pango_attr_list_new ();
+ PangoAttrList attrs;
GSList *run_attrs;
PangoItem *item;
PangoGlyphString *glyphs;
@@ -309,6 +310,8 @@ shape_ellipsis (EllipsizeState *state)
int len;
int i;
+ _pango_attr_list_init (&attrs);
+
/* Create/reset state->ellipsis_run
*/
if (!state->ellipsis_run)
@@ -333,7 +336,7 @@ shape_ellipsis (EllipsizeState *state)
attr->start_index = 0;
attr->end_index = G_MAXINT;
- pango_attr_list_insert (attrs, attr);
+ pango_attr_list_insert (&attrs, attr);
}
g_slist_free (run_attrs);
@@ -341,7 +344,7 @@ shape_ellipsis (EllipsizeState *state)
fallback = pango_attr_fallback_new (FALSE);
fallback->start_index = 0;
fallback->end_index = G_MAXINT;
- pango_attr_list_insert (attrs, fallback);
+ pango_attr_list_insert (&attrs, fallback);
/* First try using a specific ellipsis character in the best matching font
*/
@@ -350,7 +353,7 @@ shape_ellipsis (EllipsizeState *state)
else
ellipsis_text = "\342\200\246"; /* U+2026: HORIZONTAL ELLIPSIS */
- item = itemize_text (state, ellipsis_text, attrs);
+ item = itemize_text (state, ellipsis_text, &attrs);
/* If that fails we use "..." in the first matching font
*/
@@ -365,10 +368,10 @@ shape_ellipsis (EllipsizeState *state)
((PangoAttrInt *)fallback)->value = TRUE;
ellipsis_text = "...";
- item = itemize_text (state, ellipsis_text, attrs);
+ item = itemize_text (state, ellipsis_text, &attrs);
}
- pango_attr_list_unref (attrs);
+ _pango_attr_list_destroy (&attrs);
state->ellipsis_run->item = item;
diff --git a/pango/pango-attributes-private.h b/pango/pango-attributes-private.h
index 38e4525d..efeb88cd 100644
--- a/pango/pango-attributes-private.h
+++ b/pango/pango-attributes-private.h
@@ -28,6 +28,15 @@ struct _PangoAttrIterator
guint end_index;
};
+struct _PangoAttrList
+{
+ guint ref_count;
+ GSList *attributes;
+ GSList *attributes_tail;
+};
+
+void _pango_attr_list_init (PangoAttrList *list);
+void _pango_attr_list_destroy (PangoAttrList *list);
void _pango_attr_list_get_iterator (PangoAttrList *list,
PangoAttrIterator *iterator);
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 98e26872..5ac955c4 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -37,13 +37,6 @@
#include "pango-attributes-private.h"
#include "pango-impl-utils.h"
-struct _PangoAttrList
-{
- guint ref_count;
- GSList *attributes;
- GSList *attributes_tail;
-};
-
static PangoAttribute *pango_attr_color_new (const PangoAttrClass *klass,
guint16 red,
guint16 green,
@@ -1313,6 +1306,14 @@ G_DEFINE_BOXED_TYPE (PangoAttrList, pango_attr_list,
pango_attr_list_copy,
pango_attr_list_unref);
+void
+_pango_attr_list_init (PangoAttrList *list)
+{
+ list->ref_count = 1;
+ list->attributes = NULL;
+ list->attributes_tail = NULL;
+}
+
/**
* pango_attr_list_new:
*
@@ -1326,9 +1327,7 @@ pango_attr_list_new (void)
{
PangoAttrList *list = g_slice_new (PangoAttrList);
- list->ref_count = 1;
- list->attributes = NULL;
- list->attributes_tail = NULL;
+ _pango_attr_list_init (list);
return list;
}
@@ -1354,6 +1353,23 @@ pango_attr_list_ref (PangoAttrList *list)
return list;
}
+void
+_pango_attr_list_destroy (PangoAttrList *list)
+{
+ GSList *tmp_list;
+
+ tmp_list = list->attributes;
+ while (tmp_list)
+ {
+ PangoAttribute *attr = tmp_list->data;
+ tmp_list = tmp_list->next;
+
+ attr->klass->destroy (attr);
+ }
+
+ g_slist_free (list->attributes);
+}
+
/**
* pango_attr_list_unref:
* @list: (nullable): a #PangoAttrList, may be %NULL
@@ -1365,8 +1381,6 @@ pango_attr_list_ref (PangoAttrList *list)
void
pango_attr_list_unref (PangoAttrList *list)
{
- GSList *tmp_list;
-
if (list == NULL)
return;
@@ -1374,17 +1388,7 @@ pango_attr_list_unref (PangoAttrList *list)
if (g_atomic_int_dec_and_test ((int *) &list->ref_count))
{
- tmp_list = list->attributes;
- while (tmp_list)
- {
- PangoAttribute *attr = tmp_list->data;
- tmp_list = tmp_list->next;
-
- attr->klass->destroy (attr);
- }
-
- g_slist_free (list->attributes);
-
+ _pango_attr_list_destroy (list);
g_slice_free (PangoAttrList, list);
}
}
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 09132a45..f6d37068 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3069,7 +3069,7 @@ ensure_tab_width (PangoLayout *layout)
GList *items;
PangoAttribute *attr;
PangoAttrList *layout_attrs;
- PangoAttrList *tmp_attrs;
+ PangoAttrList tmp_attrs;
PangoAttrIterator iter;
PangoFontDescription *font_desc = pango_font_description_copy_static
(pango_context_get_font_description (layout->context));
PangoLanguage *language;
@@ -3078,19 +3078,19 @@ ensure_tab_width (PangoLayout *layout)
_pango_attr_list_get_iterator (layout_attrs, &iter);
pango_attr_iterator_get_font (&iter, font_desc, &language, NULL);
- tmp_attrs = pango_attr_list_new ();
+ _pango_attr_list_init (&tmp_attrs);
attr = pango_attr_font_desc_new (font_desc);
pango_font_description_free (font_desc);
- pango_attr_list_insert_before (tmp_attrs, attr);
+ pango_attr_list_insert_before (&tmp_attrs, attr);
if (language)
{
attr = pango_attr_language_new (language);
- pango_attr_list_insert_before (tmp_attrs, attr);
+ pango_attr_list_insert_before (&tmp_attrs, attr);
}
- items = pango_itemize (layout->context, " ", 0, 1, tmp_attrs, NULL);
+ items = pango_itemize (layout->context, " ", 0, 1, &tmp_attrs, NULL);
_pango_attr_iterator_destroy (&iter);
if (layout_attrs != layout->attrs)
@@ -3098,7 +3098,7 @@ ensure_tab_width (PangoLayout *layout)
pango_attr_list_unref (layout_attrs);
layout_attrs = NULL;
}
- pango_attr_list_unref (tmp_attrs);
+ _pango_attr_list_destroy (&tmp_attrs);
item = items->data;
pango_shape (" ", 8, &item->analysis, glyphs);
@@ -3466,18 +3466,18 @@ get_need_hyphen (PangoItem *item,
const char *p;
gboolean prev_space;
gboolean prev_hyphen;
- PangoAttrList *attrs;
+ PangoAttrList attrs;
PangoAttrIterator iter;
GSList *l;
- attrs = pango_attr_list_new ();
+ _pango_attr_list_init (&attrs);
for (l = item->analysis.extra_attrs; l; l = l->next)
{
PangoAttribute *attr = l->data;
if (attr->klass->type == PANGO_ATTR_INSERT_HYPHENS)
- pango_attr_list_change (attrs, pango_attribute_copy (attr));
+ pango_attr_list_change (&attrs, pango_attribute_copy (attr));
}
- _pango_attr_list_get_iterator (attrs, &iter);
+ _pango_attr_list_get_iterator (&attrs, &iter);
for (i = 0, p = text + item->offset; i < item->num_chars; i++, p = g_utf8_next_char (p))
{
@@ -3563,7 +3563,7 @@ get_need_hyphen (PangoItem *item,
}
_pango_attr_iterator_destroy (&iter);
- pango_attr_list_unref (attrs);
+ _pango_attr_list_destroy (&attrs);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]