in reply to Re^3: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
in thread Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

That code does copy —note the assignment operator— but I think COW wouldn't help there either because I think the string would be stolen from the temp rather than copied.
  • Comment on Re^4: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

Replies are listed 'Best First'.
Re^5: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
by ikegami (Patriarch) on Apr 14, 2015 at 18:42 UTC
    Whoa, why the downvotes? Rephrased in case it was confusing.

      No idea about the downvote, but with no comment to go with it, you might as well pretend it's not there. And yes, I do agree that this code probably falls out of COW's scope (that's what I meant by "not copied from one variable to another"), as I said I overlooked that part.

        I didn't say COW couldn't happen here; I said I didn't think COW would help here.

        I'm not sure what you think is being assigned from, but it is indeed a scalar, and thus COW could apply. However, if it does, it might simply replace another pre-existing optimization. This optimization allows a scalar to steal the string buffer of the scalar being assigned to it (i.e. copy the pointer instead of copying the whole buffer). This is only done if the scalar being assigned is a "temp" about to be destroyed (I'm sure what the exact condition is.)