C++ PATCH for c++/68422 (sizeof... slow to evaluate)
Jason Merrill
jason@redhat.com
Thu Nov 19 22:28:00 GMT 2015
This turns out to be because we represent sizeof... as a sizeof a pack
expansion internally, and we generated a full new pack expansion one
element at a time rather than just look at how many elements there were
in the argument pack.
We already had an optimization in tsubst_parameter_pack to recognize
when the pack expansion we're asking for will be the same as one of the
argument packs, but we weren't doing it for expressions because we might
need to convert_from_reference the elements. This patch improves the
optimization to recognize when we won't need to worry about that, and
therefore handle more expression pack expansions, which fixes the
quadratic behavior on the testcase.
But we'd like sizeof... to be fast for packs of references as well, so I
added a flag to EXPR_PACK_EXPANSION for sizeof... so we can always just
return the argument pack. Surprisingly, this provided a small but
consistent further speedup for the testcase.
Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 68422.patch
Type: text/x-patch
Size: 3658 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20151119/ba51453a/attachment.bin>
More information about the Gcc-patches
mailing list