#4820 closed Bugs (invalid)
any swaps inefficiently
Reported by: | Owned by: | nasonov | |
---|---|---|---|
Milestone: | To Be Determined | Component: | any |
Version: | Boost 1.44.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
Apologies if this isn't a bug - I am quite new to boost, however I checked in the IRC channel and it doesn't seem like this is a total non-starter.
It seems that if you simply call swap, std::swap is called, resulting in an inefficient swapping operation. For example:
Big b1, b2; any a1=b1, a2=b2;
swap(a1,a2); Calls std::swap, invokes three copy constructors
I've attached a demonstration file, which I compiled with gcc.
Seems like can be easily solved with an overloaded std::swap, but I know little about boost, so I'll leave that for the experts :)
Attachments (1)
Change History (3)
by , 12 years ago
comment:1 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
As I explained on IRC, this is not inefficient. Two copy ctor calls happen in the construction of the boost::any objects.
comment:2 by , 12 years ago
To clarify, when I run this there are in fact 5 copy constructor calls, 3 of which were generated by swap.
I have been assured that this is just me not turning on compiler optimisations, or not using boost::swap. However, even with the -o3 switch in gcc, and even with boost::swap, I still get 3 copy constructor calls. Since the best thing to do is just to swap over the pointers, I expected none.
demo of any::swap