diff options
author | Stanislav Mayorov <[email protected]> | 2018-12-13 11:39:16 +0700 |
---|---|---|
committer | John Högberg <[email protected]> | 2019-01-10 09:40:27 +0100 |
commit | 46c7a85d70ee6d060a393ca4b22b06eef6fbb324 (patch) | |
tree | 38212f3401c5c5c9d839ca65f906112b1cc51ca6 /erts/emulator/beam/bif.c | |
parent | a56bc7180c639f1f08355f22e22cf539db16982c (diff) | |
download | otp-46c7a85d70ee6d060a393ca4b22b06eef6fbb324.tar.gz otp-46c7a85d70ee6d060a393ca4b22b06eef6fbb324.tar.bz2 otp-46c7a85d70ee6d060a393ca4b22b06eef6fbb324.zip |
Implement integer_to_list/2 and integer_to_binary/2 as CIFs
This makes them roughly as fast as integer_to_list/1 and
integer_to_binary/1.
Diffstat (limited to 'erts/emulator/beam/bif.c')
-rw-r--r-- | erts/emulator/beam/bif.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index 45b75a4e31..f1fac7f8d0 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -2883,6 +2883,39 @@ BIF_RETTYPE integer_to_list_1(BIF_ALIST_1) return res; } +BIF_RETTYPE integer_to_list_2(BIF_ALIST_2) +{ + Eterm res; + int base; + + if (is_not_integer(BIF_ARG_1) || is_not_integer(BIF_ARG_2)) { + BIF_ERROR(BIF_P, BADARG); + } + + base = unsigned_val(BIF_ARG_2); + if (base < 2 || base > 36) { + BIF_ERROR(BIF_P, BADARG); + } + + res = integer_to_list(BIF_P, BIF_ARG_1, base); + + if (is_non_value(res)) { + Eterm args[2]; + args[0] = BIF_ARG_1; + args[1] = BIF_ARG_2; + return erts_schedule_bif(BIF_P, + args, + BIF_I, + integer_to_list_2, + ERTS_SCHED_DIRTY_CPU, + am_erlang, + am_integer_to_list, + 2); + } + + return res; +} + /**********************************************************************/ /* |