From b4f73263b11efd7298ca320a6025952b2be99066 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 11 Mar 2019 15:54:47 +0100 Subject: Get rid of useless setelement in array module --- lib/stdlib/src/array.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/src/array.erl b/lib/stdlib/src/array.erl index 939b1fb488..904d977faf 100644 --- a/lib/stdlib/src/array.erl +++ b/lib/stdlib/src/array.erl @@ -129,8 +129,9 @@ -define(LEAFSIZE, 10). % the "base" -define(NODESIZE, ?LEAFSIZE). % (no reason to have a different size) -define(NODEPATTERN(S), {_,_,_,_,_,_,_,_,_,_,S}). % NODESIZE+1 elements! --define(NEW_NODE(S), % beware of argument duplication! - setelement((?NODESIZE+1),erlang:make_tuple((?NODESIZE+1),(S)),(S))). +-define(NEW_NODE(E,S), % general case (currently unused) + setelement((?NODESIZE+1),erlang:make_tuple((?NODESIZE+1),(E)),(S))). +-define(NEW_NODE(S), erlang:make_tuple((?NODESIZE+1),(S))). % when E = S -define(NEW_LEAF(D), erlang:make_tuple(?LEAFSIZE,(D))). -define(NODELEAFS, ?NODESIZE*?LEAFSIZE). -- cgit v1.2.3 From 0eefa1868ba65771077e57bafaa11b1834af7522 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 11 Mar 2019 15:57:36 +0100 Subject: Clarify comments in array module --- lib/stdlib/src/array.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/src/array.erl b/lib/stdlib/src/array.erl index 904d977faf..a65f7eb747 100644 --- a/lib/stdlib/src/array.erl +++ b/lib/stdlib/src/array.erl @@ -126,8 +126,8 @@ %% per write than base 10, but the speedup is only 21%.) -define(DEFAULT, undefined). --define(LEAFSIZE, 10). % the "base" --define(NODESIZE, ?LEAFSIZE). % (no reason to have a different size) +-define(LEAFSIZE, 10). % the "base" (assumed to be > 1) +-define(NODESIZE, ?LEAFSIZE). % must not be LEAFSIZE-1; keep same as leaf -define(NODEPATTERN(S), {_,_,_,_,_,_,_,_,_,_,S}). % NODESIZE+1 elements! -define(NEW_NODE(E,S), % general case (currently unused) setelement((?NODESIZE+1),erlang:make_tuple((?NODESIZE+1),(E)),(S))). -- cgit v1.2.3 From a52bd506e6b050b028f734cb9f90cf2e0a497d02 Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 11 Mar 2019 16:01:22 +0100 Subject: Skip useless test in grow loop in array module --- lib/stdlib/src/array.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/stdlib/src/array.erl b/lib/stdlib/src/array.erl index a65f7eb747..32bc2a3372 100644 --- a/lib/stdlib/src/array.erl +++ b/lib/stdlib/src/array.erl @@ -606,7 +606,7 @@ grow(I, E, M) -> grow_1(I, E, M). grow_1(I, E, M) when I >= M -> - grow(I, setelement(1, ?NEW_NODE(M), E), ?extend(M)); + grow_1(I, setelement(1, ?NEW_NODE(M), E), ?extend(M)); grow_1(_I, E, M) -> {E, M}. -- cgit v1.2.3 From df0142c1da4966728f7b37fa779a1003b22fd72e Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 11 Mar 2019 16:16:42 +0100 Subject: Fix array tests hardcoded to node/leaf sizes --- lib/stdlib/src/array.erl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/src/array.erl b/lib/stdlib/src/array.erl index 32bc2a3372..1504326c61 100644 --- a/lib/stdlib/src/array.erl +++ b/lib/stdlib/src/array.erl @@ -1632,12 +1632,11 @@ foldl_test_() -> ?_assert(foldl(Sum, 0, from_list(lists:seq(0,10))) =:= 55), ?_assert(foldl(Reverse, [], from_list(lists:seq(0,1000))) =:= lists:reverse(lists:seq(0,1000))), - ?_assert({999,[N0*100+1+2,N0*2+1+1,0]} =:= - foldl(Vals, {0,[]}, + ?_assertEqual({N0*100+1-2,[N0*100+1+2,N0*2+1+1,0]}, + foldl(Vals, {0,[]}, set(N0*100+1,2, set(N0*2+1,1, set(0,0,new()))))) - ]. -endif. @@ -1787,12 +1786,11 @@ foldr_test_() -> ?_assert(foldr(Sum, 0, from_list(lists:seq(0,10))) =:= 55), ?_assert(foldr(List, [], from_list(lists:seq(0,1000))) =:= lists:seq(0,1000)), - ?_assert({999,[0,N0*2+1+1,N0*100+1+2]} =:= - foldr(Vals, {0,[]}, + ?_assertEqual({N0*100+1-2,[0,N0*2+1+1,N0*100+1+2]}, + foldr(Vals, {0,[]}, set(N0*100+1,2, set(N0*2+1,1, set(0,0,new()))))) - ]. -endif. -- cgit v1.2.3