1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Make use of htonl() and <nowiki>__builtin_bswap32()</nowiki> for faster

implementations of sqlite3Get4byte() and sqlite3Put4byte().

FossilOrigin-Name: bc27ebd7f73e9fc8e00da6ec82632e439fcce812
This commit is contained in:
drh
2015-06-30 12:47:09 +00:00
parent 3169906d06
commit 5372e4d4f9
3 changed files with 31 additions and 7 deletions

View File

@@ -1078,14 +1078,38 @@ 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 defined(_MSC_VER)
u32 x;
memcpy(&x,p,4);
return htonl(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 defined(_MSC_VER)
u32 x = htonl(v);
memcpy(&x,p,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
}