diff options
author | Björn Gustavsson <[email protected]> | 2015-02-23 10:04:12 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-02-23 10:04:12 +0100 |
commit | 343a1d3f41ca9655d032e7946b0334b6a361d6be (patch) | |
tree | 434f925c31957ace7cfa416f373a6dca61c29c61 /lib/stdlib | |
parent | bb86b0f831348d8ecd8baeb5e006c0467a540441 (diff) | |
parent | e8398cce2451f6323eb5d8cce4adf4d5b69bb098 (diff) | |
download | otp-343a1d3f41ca9655d032e7946b0334b6a361d6be.tar.gz otp-343a1d3f41ca9655d032e7946b0334b6a361d6be.tar.bz2 otp-343a1d3f41ca9655d032e7946b0334b6a361d6be.zip |
Merge branch 'josevalim/stdlib/dict'
* josevalim/stdlib/dict:
Short-circuit common dict operations
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/dict.erl | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/stdlib/src/dict.erl b/lib/stdlib/src/dict.erl index cf8fb3114a..5a9f63c5e2 100644 --- a/lib/stdlib/src/dict.erl +++ b/lib/stdlib/src/dict.erl @@ -417,6 +417,8 @@ on_bucket(F, T, Slot) -> %% could have implemented map and filter using fold but these are %% faster. We hope! +fold_dict(F, Acc, #dict{size=0}) when is_function(F, 3) -> + Acc; fold_dict(F, Acc, D) -> Segs = D#dict.segs, fold_segs(F, Acc, Segs, tuple_size(Segs)). @@ -434,6 +436,8 @@ fold_bucket(F, Acc, [?kv(Key,Val)|Bkt]) -> fold_bucket(F, F(Key, Val, Acc), Bkt); fold_bucket(F, Acc, []) when is_function(F, 3) -> Acc. +map_dict(F, #dict{size=0} = Dict) when is_function(F, 2) -> + Dict; map_dict(F, D) -> Segs0 = tuple_to_list(D#dict.segs), Segs1 = map_seg_list(F, Segs0), @@ -453,6 +457,8 @@ map_bucket(F, [?kv(Key,Val)|Bkt]) -> [?kv(Key,F(Key, Val))|map_bucket(F, Bkt)]; map_bucket(F, []) when is_function(F, 2) -> []. +filter_dict(F, #dict{size=0} = Dict) when is_function(F, 2) -> + Dict; filter_dict(F, D) -> Segs0 = tuple_to_list(D#dict.segs), {Segs1,Fc} = filter_seg_list(F, Segs0, [], 0), |