This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Extending Temporary buffer for rvalues
- From: Christopher Jefferson <caj at cs dot st-andrews dot ac dot uk>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 26 Aug 2009 15:11:11 +0100
- Subject: Extending Temporary buffer for rvalues
I wanted to post this patch separate from my other work, as it might
be controversial (but hopefully isn't).
This patch changes _Temporary_buffer so that rather than using
uninitalised_fill_n, it 'moves' the first value from the range being
sorted along the uninitalised range, then back to where it started.
This isn't slow -- we already special case PODs so there isn't really
any opportunity for the compiler to change the code into a memset or
something similar.
I believe also the code is fine from the point of view of correctness.
One problem is that if one of these constructors throws, the '*first'
value is lost. However, if any constructor throws once the main body
of the algorithm has begun, values could still be lost before, even in
C++03, so I do not believe this harms the algorithm.
If this patch is acceptable, then the rest of the C++0x changes to
sort are, I believe, non-contraversal.
If this patch is OK, you are welcome to apply this patch as is, or
wait for a large patch which subsumes it.
Thanks, Chris
Attachment:
temporary_buffer_rvalue.patch
Description: Binary data
2009-08-26 Chris Jefferson <chris@bubblescope.net>
* include/bits/stl_tempbuf.h
(_Temporary_buffer::_Temporary_buffer) :
Extend to work with move-only types.
* testsuite/25_algorithm/stable_sort/mem_check.cc : New
* testsuite/util/testsuite_hooks.h : Add operator< to copy_tracker.