[PATCH] PR67085 move comparison functions in heap operations

Jonathan Wakely jwakely@redhat.com
Thu Jan 19 23:08:00 GMT 2017


On 19/01/17 20:24 +0000, Jonathan Wakely wrote:
>On 19/01/17 18:50 +0000, Jonathan Wakely wrote:
>>On 19/01/17 18:28 +0000, Jonathan Wakely wrote:
>>>@@ -397,7 +401,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>>     while (__last - __first > 1)
>>>	{
>>>	  --__last;
>>>-	  std::__pop_heap(__first, __last, __last, __comp);
>>>+	  std::__pop_heap(__first, __last, __last, _GLIBCXX_MOVE(__comp));
>>
>>Oops, we can't move from the functor in a loop, it might be invalid
>>after the first move. Fix coming asap.
>
>Unfortunately this adds some more copies to my testcase. I have
>another idea how to avoid that though.
>
>This also adds an extra (safe) move in __is_heap.

I hope this is the last change needed for this bug. This avoids the
__iter_xxx_iter() generator functions and constructs the function
objects directly as local variables (to avoid copies in the arguments
and return values of the generators), and then passes them as lvalues
to the internal heap algos (to avoid copies in the algo argument
lists).

We can probably do more in <bits/predefined_ops.h> to avoid passing
things by value, at least for C++11 and later. We can probably also
avoid the generator functions in stl_algo.h and stl_algobase.h but I'm
not going to try to do that now.

I also tried passing the heap algos' _Tp arguments by reference, as
suggested by PR 51965, but that caused some regressions. I'll revisit
that another time.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 13068 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20170119/0a0a62e5/attachment.bin>


More information about the Libstdc++ mailing list