diff options
author | drh <drh@noemail.net> | 2015-06-30 15:10:29 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-06-30 15:10:29 +0000 |
commit | da6d3e2117fd2ab1cbcc0f21ac5839d08d04344e (patch) | |
tree | fab3e1861926f343b3d81296e4a8fa6d14f684cd /src/util.c | |
parent | 3169906d061c60903ca654b5bdbc6355f7cee1e7 (diff) | |
parent | ad265296ffbaa5d238f3fd9c4e09398be92c3af1 (diff) | |
download | sqlite-da6d3e2117fd2ab1cbcc0f21ac5839d08d04344e.tar.gz sqlite-da6d3e2117fd2ab1cbcc0f21ac5839d08d04344e.zip |
Make use of built-in bswap32() and bswap16() functions in GCC/Clang for a
significant performance improvement there.
FossilOrigin-Name: 8bfcda3d10aec864d71d12a1248c37e4db6f8899
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 8fdaf2678..4e029b0e0 100644 --- a/src/util.c +++ b/src/util.c @@ -1078,14 +1078,31 @@ int sqlite3VarintLen(u64 v){ ** Read or write a four-byte big-endian integer value. */ u32 sqlite3Get4byte(const u8 *p){ +#if SQLITE_BYTEORDER==4321 + u32 x; + memcpy(&x,p,4); + return x; +#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) + u32 x; + memcpy(&x,p,4); + return __builtin_bswap32(x); +#else testcase( p[0]&0x80 ); return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; +#endif } void sqlite3Put4byte(unsigned char *p, u32 v){ +#if SQLITE_BYTEORDER==4321 + memcpy(p,&v,4); +#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) + u32 x = __builtin_bswap32(v); + memcpy(p,&x,4); +#else p[0] = (u8)(v>>24); p[1] = (u8)(v>>16); p[2] = (u8)(v>>8); p[3] = (u8)v; +#endif } |