c++: Tweak reshape_init_array_1 [PR94124]
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Mar 2020 07:28:05 +0000 (08:28 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 12 Mar 2020 07:28:05 +0000 (08:28 +0100)
commit4069adf4bbc90d16b603e0308b48499c36b2b637
treeeb80f36b3b6fac6badfaf0f01619bbc06ae8ae05
parentaedb4c8fc77034a3a009bee887691d5727658627
c++: Tweak reshape_init_array_1 [PR94124]

Isn't it wasteful to first copy perhaps a large constructor (recursively)
and then truncate it to very few elts (zero in this case)?

> We should certainly avoid copying if they're the same.  The code above for
> only copying the bits that aren't going to be thrown away seems pretty
> straightforward, might as well use it even if the savings aren't likely to
> be large.

Calling vec_safe_truncate with the same number of elts the vector already
has is a nop, so IMHO we just should make sure we only unshare if it
changed.

2020-03-12  Jakub Jelinek  <jakub@redhat.com>

PR c++/94124
* decl.c (reshape_init_array_1): Don't unshare constructor if there
aren't any trailing zero elts, otherwise only unshare the first
nelts.
gcc/cp/ChangeLog
gcc/cp/decl.c