From 49e7607fa0c8dc1d9040b63e46531bef0383ceeb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 Aug 2006 20:15:32 +0000 Subject: [PATCH] Simplified swap bytes code to make it more efficient. --- include/osg/Endian | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/include/osg/Endian b/include/osg/Endian index 3bf92ac3f..7673cdfb3 100644 --- a/include/osg/Endian +++ b/include/osg/Endian @@ -42,46 +42,37 @@ inline void swapBytes( char* in, unsigned int size ) { std::swap(*start++,*end--); } - } inline void swapBytes2( char* in ) { - char* start = in; - char* end = start+1; - std::swap(*start,*end); + std::swap(in[0],in[1]); } inline void swapBytes4( char* in ) { - char* start = in; - char* end = start+3; - std::swap(*start++,*end--); - std::swap(*start,*end); + std::swap(in[0],in[3]); + std::swap(in[1],in[2]); } inline void swapBytes8( char* in ) { - char* start = in; - char* end = start+7; - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start,*end); + std::swap(in[0],in[7]); + std::swap(in[1],in[6]); + std::swap(in[2],in[5]); + std::swap(in[3],in[4]); } inline void swapBytes16( char* in ) { - char* start = in; - char* end = start+15; - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start++,*end--); - std::swap(*start,*end); + std::swap(in[0],in[15]); + std::swap(in[1],in[14]); + std::swap(in[2],in[13]); + std::swap(in[3],in[12]); + std::swap(in[4],in[11]); + std::swap(in[5],in[10]); + std::swap(in[6],in[9]); + std::swap(in[7],in[8]); } }