aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-06-30 12:47:09 +0000
committerdrh <drh@noemail.net>2015-06-30 12:47:09 +0000
commit5372e4d4f9a6407de9075e29ecbd0730dc6193c7 (patch)
tree6f892382b7e5614e040785694eeec1ed129ae4b9 /src
parent3169906d061c60903ca654b5bdbc6355f7cee1e7 (diff)
downloadsqlite-5372e4d4f9a6407de9075e29ecbd0730dc6193c7.tar.gz
sqlite-5372e4d4f9a6407de9075e29ecbd0730dc6193c7.zip
Make use of htonl() and <nowiki>__builtin_bswap32()</nowiki> for faster
implementations of sqlite3Get4byte() and sqlite3Put4byte(). FossilOrigin-Name: bc27ebd7f73e9fc8e00da6ec82632e439fcce812
Diffstat (limited to 'src')
-rw-r--r--src/util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 8fdaf2678..f2d3e91e7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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
}