Skip to content

Commit 234581b

Browse files
authored
Improve protability for PG18 (#5)
1 parent 30e63f7 commit 234581b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/city.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// compromising on hash quality.
4747

4848
#include "spqrhash.h"
49-
#include <byteswap.h>
49+
#include "port/pg_bswap.h"
5050

5151
#if defined __GNUC__ && __GNUC__ >= 3
5252
#define HAVE_BUILTIN_EXPECT 1
@@ -61,8 +61,13 @@ typedef struct city_uint128 city_uint128;
6161
static inline uint64_t Uint128Low64(const city_uint128 x) { return x.first; }
6262
static inline uint64_t Uint128High64(const city_uint128 x) { return x.second; }
6363

64-
#define uint32_in_expected_order(x) le32toh(x)
65-
#define uint64_in_expected_order(x) le64toh(x)
64+
#ifdef WORDS_BIGENDIAN
65+
#define uint32_in_expected_order(x) pg_bswap32(x)
66+
#define uint64_in_expected_order(x) pg_bswap64(x)
67+
#else
68+
#define uint32_in_expected_order(x) (x)
69+
#define uint64_in_expected_order(x) (x)
70+
#endif
6671

6772
#if !defined(LIKELY)
6873
#if HAVE_BUILTIN_EXPECT
@@ -213,9 +218,9 @@ static uint32_t CityHash32(const char *s, size_t len) {
213218
h = Rotate32(h, 19);
214219
h = h * 5 + 0xe6546b64;
215220
g ^= a4;
216-
g = bswap_32(g) * 5;
221+
g = pg_bswap32(g) * 5;
217222
h += a4 * 5;
218-
h = bswap_32(h);
223+
h = pg_bswap32(h);
219224
f += a0;
220225
tmp = f;
221226
f = g;

0 commit comments

Comments
 (0)