aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorMichał Muskała <[email protected]>2018-07-17 18:38:10 +0200
committerMichał Muskała <[email protected]>2018-07-17 19:30:49 +0200
commit0916c5c6e536affca1f6f0c7693d68fb64843c1c (patch)
tree1323d1656dc8770e8b9e24f997e323f77720022e /lib/stdlib
parent0e9c319480d9cfb778b654bf2cd71e7bd31464f9 (diff)
downloadotp-0916c5c6e536affca1f6f0c7693d68fb64843c1c.tar.gz
otp-0916c5c6e536affca1f6f0c7693d68fb64843c1c.tar.bz2
otp-0916c5c6e536affca1f6f0c7693d68fb64843c1c.zip
maps:new/0 is no longer a BIF
Implementing it in Erlang allows taking advantage of the literal pool optimisation, this means the function implemented in Erlang does no allocations, while the BIF had to allocate new map each time it was called. Benchmarks show the function is also slightly faster now.
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/src/maps.erl16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index 60463feec2..6f5553c769 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -21,7 +21,7 @@
-module(maps).
-export([get/3, filter/2,fold/3,
- map/2, size/1,
+ map/2, size/1, new/0,
update_with/3, update_with/4,
without/2, with/2,
iterator/1, next/1]).
@@ -29,7 +29,7 @@
%% BIFs
-export([get/2, find/2, from_list/1,
is_key/2, keys/1, merge/2,
- new/0, put/3, remove/2, take/2,
+ put/3, remove/2, take/2,
to_list/1, update/3, values/1]).
-opaque iterator() :: {term(), term(), iterator()}
@@ -91,13 +91,6 @@ keys(_) -> erlang:nif_error(undef).
merge(_,_) -> erlang:nif_error(undef).
-
--spec new() -> Map when
- Map :: map().
-
-new() -> erlang:nif_error(undef).
-
-
%% Shadowed by erl_bif_types: maps:put/3
-spec put(Key,Value,Map1) -> Map2 when
Key :: term(),
@@ -157,6 +150,11 @@ values(_) -> erlang:nif_error(undef).
%% End of BIFs
+-spec new() -> Map when
+ Map :: #{}.
+
+new() -> #{}.
+
-spec update_with(Key,Fun,Map1) -> Map2 when
Key :: term(),
Map1 :: map(),