Boost logo

Boost :

Subject: Re: [boost] [Endian] Performance
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-09-06 13:13:05

On 06/09/2011 18:28, Phil Endecott wrote:

> Well std::reverse is in-place, and this particular code is not. But yes,
> std::reverse could be used for some of Beman's functions, and some sort
> of std::copy with reverse iterators could be used here. There are also
> places where the code could be more concise if std::swap were used.

Well you could copy src into target, then reverse target in place.
But I guess that would actually be slower.

> Fundamentally though, I don't think that casting to bytes is the right
> way to do this

It's a way that works for all types, even non-integer ones (i.e.
It's good for a base implementation.

> shifts and bitwise ops seem to produce better code

The best code depends on the actual type and architecture.
The best thing to do, for performance, is to call specialized functions
for each type, such as built-ins or intrinsics.

I don't think this is really important though.

>, and
> involve less worrying casting.

Nothing to worry about here. char* is allowed to alias to permit just that.

Boost list run by bdawes at, gregod at, cpdaniel at, john at