[PATCH][C++] Save memory/time when folding CONSTRUCTORs
Jakub Jelinek
jakub@redhat.com
Wed Feb 1 15:22:00 GMT 2017
On Wed, Feb 01, 2017 at 04:18:49PM +0100, Richard Biener wrote:
> 2017-02-01 Richard Biener <rguenther@suse.de>
>
> PR cp/14179
> cp/
> * cp-gimplify.c (cp_fold): When folding a CONSTRUCTOR copy
> it lazily on the first changed element only and copy it
> fully upfront, only storing changed elements.
>
> Index: gcc/cp/cp-gimplify.c
> ===================================================================
> --- gcc/cp/cp-gimplify.c (revision 245096)
> +++ gcc/cp/cp-gimplify.c (working copy)
> @@ -2358,15 +2358,11 @@ cp_fold (tree x)
> {
> unsigned i;
> constructor_elt *p;
> - bool changed = false;
> vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (x);
> vec<constructor_elt, va_gc> *nelts = NULL;
> - vec_safe_reserve (nelts, vec_safe_length (elts));
> FOR_EACH_VEC_SAFE_ELT (elts, i, p)
> {
> tree op = cp_fold (p->value);
> - constructor_elt e = { p->index, op };
> - nelts->quick_push (e);
> if (op != p->value)
> {
> if (op == error_mark_node)
> @@ -2375,10 +2371,12 @@ cp_fold (tree x)
> changed = false;
> break;
> }
> - changed = true;
> + if (nelts == NULL)
> + nelts = elts->copy ();
> + (*nelts)[i].value = op;
> }
> }
> - if (changed)
> + if (nelts)
> x = build_constructor (TREE_TYPE (x), nelts);
> else
> vec_free (nelts);
vec_free (nelts); doesn't make sense in this case though,
so I'd also remove the last 2 lines.
Jakub
More information about the Gcc-patches
mailing list