aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/bif.c
diff options
context:
space:
mode:
authorGuilherme Andrade <[email protected]>2017-04-19 00:43:37 +0100
committerGuilherme Andrade <[email protected]>2017-04-19 01:25:35 +0100
commit0835f40ae25f97360dc393928796387d3cd6b16e (patch)
tree22b56cc3a6cb90d79efb394ecd1fab58e1182f8c /erts/emulator/beam/bif.c
parent6124bfc9b61227a5e82f1d7273d0895e909aac6e (diff)
downloadotp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.gz
otp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.bz2
otp-0835f40ae25f97360dc393928796387d3cd6b16e.zip
erts: Add enif_phash2 and enif_phash2_ranged
These allow one to hash VM terms from NIF code.
Diffstat (limited to 'erts/emulator/beam/bif.c')
-rw-r--r--erts/emulator/beam/bif.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index 214de3652f..d59adc18d6 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -4888,7 +4888,6 @@ BIF_RETTYPE phash2_1(BIF_ALIST_1)
BIF_RETTYPE phash2_2(BIF_ALIST_2)
{
Uint32 hash;
- Uint32 final_hash;
Uint32 range;
/* Check for special case 2^32 */
@@ -4901,23 +4900,19 @@ BIF_RETTYPE phash2_2(BIF_ALIST_2)
}
range = (Uint32) u;
}
- hash = make_hash2(BIF_ARG_1);
- if (range) {
- final_hash = hash % range; /* [0..range-1] */
- } else {
- final_hash = hash;
- }
+ hash = make_hash2_within_range(BIF_ARG_1, range);
+
/*
* Return either a small or a big. Use the heap for bigs if there is room.
*/
#if defined(ARCH_64)
- BIF_RET(make_small(final_hash));
+ BIF_RET(make_small(hash));
#else
- if (IS_USMALL(0, final_hash)) {
- BIF_RET(make_small(final_hash));
+ if (IS_USMALL(0, hash)) {
+ BIF_RET(make_small(hash));
} else {
Eterm* hp = HAlloc(BIF_P, BIG_UINT_HEAP_SIZE);
- BIF_RET(uint_to_big(final_hash, hp));
+ BIF_RET(uint_to_big(hash, hp));
}
#endif
}