diff options
author | Björn-Egil Dahlberg <[email protected]> | 2013-09-19 17:48:28 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-01-28 15:56:26 +0100 |
commit | 63ef0bbfdfb70673fe7f3ce2fc6fa4f0f801747d (patch) | |
tree | 7f03c6fcc8e9c9f3bda78b3140011652cff5d6e6 /erts/emulator/beam/erl_map.c | |
parent | 92303a2e1abdf74aa3bc3af095131a59a601c45e (diff) | |
download | otp-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_map.c')
-rw-r--r-- | erts/emulator/beam/erl_map.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c index 1fd7943c30..6a59fa29b8 100644 --- a/erts/emulator/beam/erl_map.c +++ b/erts/emulator/beam/erl_map.c @@ -30,10 +30,8 @@ #include "error.h" #include "bif.h" - #include "erl_map.h" - BIF_RETTYPE map_to_list_1(BIF_ALIST_1) { if (is_map(BIF_ARG_1)) { Uint n; @@ -58,6 +56,27 @@ BIF_RETTYPE map_to_list_1(BIF_ALIST_1) { BIF_ERROR(BIF_P, BADARG); } + +/* erlang:map_size/1 + * the corresponding instruction is implemented in: + * beam/erl_bif_guard.c + */ + +BIF_RETTYPE map_size_1(BIF_ALIST_1) { + if (is_map(BIF_ARG_1)) { + Eterm *hp; + Uint hsz = 0; + map_t *mp = (map_t*)map_val(BIF_ARG_1); + Uint n = map_get_size(mp); + + erts_bld_uint(NULL, &hsz, n); + hp = HAlloc(BIF_P, hsz); + BIF_RET(erts_bld_uint(&hp, NULL, n)); + } + + BIF_ERROR(BIF_P, BADARG); +} + BIF_RETTYPE map_new_0(BIF_ALIST_0) { Eterm* hp; Eterm tup; |