diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-04-03 20:25:35 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-04-04 14:20:25 -0400 |
commit | 214e2d14be42302872dbd7e2cacf324a25d976b6 (patch) | |
tree | 797e015041bbebe891b1e0b61ed3dc0e9c4a4dd6 | |
parent | 67ee6b274048deebfb31abf539d09ef4b5e579fe (diff) | |
download | gtk+-214e2d14be42302872dbd7e2cacf324a25d976b6.tar.gz |
textbtree: Avoid malloc in one place
-rw-r--r-- | gtk/gtktextbtree.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/gtk/gtktextbtree.c b/gtk/gtktextbtree.c index 5f87ae70ad..8167366109 100644 --- a/gtk/gtktextbtree.c +++ b/gtk/gtktextbtree.c @@ -2469,16 +2469,12 @@ _gtk_text_btree_char_count (GtkTextBTree *tree) return tree->root_node->num_chars - 2; } -#define LOTSA_TAGS 1000 gboolean _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) { gboolean invisible = FALSE; /* if nobody says otherwise, it's visible */ - - int deftagCnts[LOTSA_TAGS] = { 0, }; - int *tagCnts = deftagCnts; - GtkTextTag *deftags[LOTSA_TAGS]; - GtkTextTag **tags = deftags; + int *tagCnts; + GtkTextTag **tags; int numTags; GtkTextBTreeNode *node; GtkTextLine *siblingline; @@ -2489,7 +2485,6 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) GtkTextBTree *tree; int byte_index; - line = _gtk_text_iter_get_text_line (iter); tree = _gtk_text_iter_get_btree (iter); /* Short-circuit if we've never seen a visibility tag within the @@ -2498,16 +2493,14 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) if G_LIKELY (!_gtk_text_tag_table_affects_visibility (tree->table)) return FALSE; + line = _gtk_text_iter_get_text_line (iter); + byte_index = gtk_text_iter_get_line_index (iter); numTags = gtk_text_tag_table_get_size (tree->table); - /* almost always avoid malloc, so stay out of system calls */ - if (LOTSA_TAGS < numTags) - { - tagCnts = g_new0 (int, numTags); - tags = g_new (GtkTextTag*, numTags); - } + tagCnts = g_alloca (sizeof (int) * numTags); + tags = g_alloca (sizeof (GtkTextTag *) * numTags); /* * Record tag toggles within the line of indexPtr but preceding @@ -2610,12 +2603,6 @@ _gtk_text_btree_char_is_invisible (const GtkTextIter *iter) } } - if (LOTSA_TAGS < numTags) - { - g_free (tagCnts); - g_free (tags); - } - return invisible; } |