Skip to content

Commit

Permalink
Eliminate branching in interfaces to mmh3_128
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimes committed Sep 7, 2024
1 parent 8b86dff commit 9bf6c42
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/mmh3/mmh3module.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ typedef unsigned __int64 uint64_t;
#define MMH3_32_BLOCKSIZE 12
#define MMH3_128_BLOCKSIZE 32

typedef void (*mmh3_128_func_t)(const void *key, Py_ssize_t len, uint32_t seed,
void *out);
static const mmh3_128_func_t mmh3_128_func[2] = {murmurhash3_x86_128,
murmurhash3_x64_128};

//-----------------------------------------------------------------------------
// One shot functions

Expand Down Expand Up @@ -180,12 +185,7 @@ mmh3_hash64(PyObject *self, PyObject *args, PyObject *keywds)
return NULL;
}

if (x64arch == 1) {
murmurhash3_x64_128(target_str, target_str_len, seed, result);
}
else {
murmurhash3_x86_128(target_str, target_str_len, seed, result);
}
mmh3_128_func[x64arch](target_str, target_str_len, seed, result);

PyObject *retval = Py_BuildValue(valflag[is_signed], result[0], result[1]);
return retval;
Expand Down Expand Up @@ -218,12 +218,7 @@ mmh3_hash128(PyObject *self, PyObject *args, PyObject *keywds)
return NULL;
}

if (x64arch == 1) {
murmurhash3_x64_128(target_str, target_str_len, seed, result);
}
else {
murmurhash3_x86_128(target_str, target_str_len, seed, result);
}
mmh3_128_func[x64arch](target_str, target_str_len, seed, result);

#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
result[0] = bswap_64(result[0]);
Expand Down Expand Up @@ -267,12 +262,7 @@ mmh3_hash_bytes(PyObject *self, PyObject *args, PyObject *keywds)
return NULL;
}

if (x64arch == 1) {
murmurhash3_x64_128(target_str, target_str_len, seed, result);
}
else {
murmurhash3_x86_128(target_str, target_str_len, seed, result);
}
mmh3_128_func[x64arch](target_str, target_str_len, seed, result);

#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
result[0] = bswap_64(result[0]);
Expand Down

0 comments on commit 9bf6c42

Please sign in to comment.