
Le vendredi 04 mars 2011 à 01:02 -0500, Chad Nelson a écrit :
integer_t<...> & operator+= (const integer_t<...> b) integer_t<...> & operator-= (const integer_t<...> b)
Why are these parameters passed by value?
This was mentioned in an earlier message. I didn't recall the reason then, but I've looked into it: it's partly due to Dave Abraham's "Want Speed? Pass by Value." article (possibly by misunderstanding, I'll review that in the next few days to find out), and partly because the internal COW system makes copies very cheap -- I suspect, as cheap as pass-by-reference. Most of those pass-by-value functions should probably be changed, we'll see what I come up with.
I'm pretty sure a COW copy is never cheaper than a reference copy, and probably always less cheap (given the reference count that needs incrementing).
Yes, I've reviewed the article, and it was a misunderstanding. I'll change the parameters to const references for the next release.
As Mathias said, if your benchmarks used "pass by balue" everywhere, it's not a surprise a priori that COW test case was faster. Ivan