aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_bif_guard.c
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2013-09-19 17:48:28 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-01-28 15:56:26 +0100
commit63ef0bbfdfb70673fe7f3ce2fc6fa4f0f801747d (patch)
tree7f03c6fcc8e9c9f3bda78b3140011652cff5d6e6 /erts/emulator/beam/erl_bif_guard.c
parent92303a2e1abdf74aa3bc3af095131a59a601c45e (diff)
downloadotp-63ef0bbfdfb70673fe7f3ce2fc6fa4f0f801747d.tar.gz
otp-63ef0bbfdfb70673fe7f3ce2fc6fa4f0f801747d.tar.bz2
otp-63ef0bbfdfb70673fe7f3ce2fc6fa4f0f801747d.zip
erts: Add the size-testing guard BIF map_size/1
Diffstat (limited to 'erts/emulator/beam/erl_bif_guard.c')
-rw-r--r--erts/emulator/beam/erl_bif_guard.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_bif_guard.c b/erts/emulator/beam/erl_bif_guard.c
index a715756c15..bbd8aa31d9 100644
--- a/erts/emulator/beam/erl_bif_guard.c
+++ b/erts/emulator/beam/erl_bif_guard.c
@@ -33,6 +33,7 @@
#include "bif.h"
#include "big.h"
#include "erl_binary.h"
+#include "erl_map.h"
static Eterm gc_double_to_integer(Process* p, double x, Eterm* reg, Uint live);
@@ -455,6 +456,28 @@ Eterm erts_gc_byte_size_1(Process* p, Eterm* reg, Uint live)
}
}
+Eterm erts_gc_map_size_1(Process* p, Eterm* reg, Uint live)
+{
+ Eterm arg = reg[live];
+ if (is_map(arg)) {
+ map_t *mp = (map_t*)map_val(arg);
+ Uint size = map_get_size(mp);
+ if (IS_USMALL(0, size)) {
+ return make_small(size);
+ } else {
+ Eterm* hp;
+ if (ERTS_NEED_GC(p, BIG_UINT_HEAP_SIZE)) {
+ erts_garbage_collect(p, BIG_UINT_HEAP_SIZE, reg, live);
+ }
+ hp = p->htop;
+ p->htop += BIG_UINT_HEAP_SIZE;
+ return uint_to_big(size, hp);
+ }
+ } else {
+ BIF_ERROR(p, BADARG);
+ }
+}
+
Eterm erts_gc_abs_1(Process* p, Eterm* reg, Uint live)
{
Eterm arg;