On Wed, 1 Feb 2017, Nathan Sidwell wrote: > On 02/01/2017 10:18 AM, Richard Biener wrote: > > > True. Updated patch below. > > > > Richard. > > > > 2017-02-01 Richard Biener <rguent...@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. > > Looks good, with the tweak Jakub noticed.
And one more tweak, I have to free it for the error_mark_case. (vec_free sets nelts to NULL) Richard. 2017-02-01 Richard Biener <rguent...@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,30 +2358,26 @@ 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) { x = error_mark_node; - changed = false; + vec_free (nelts); 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); break; } case TREE_VEC: