Skip to content

Commit

Permalink
Merge branch 'egil/r16/fix-delete_element/OTP-10932' into maint-r16
Browse files Browse the repository at this point in the history
* egil/r16/fix-delete_element/OTP-10932:
  erts: Refactor erlang:insert_element/3 for clarity
  erts: Fix copy error in erlang:delete_element/2
  • Loading branch information
Erlang/OTP committed Apr 4, 2013
2 parents d0e4767 + 9b25088 commit b3678dc
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions erts/emulator/beam/bif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ BIF_RETTYPE insert_element_3(BIF_ALIST_3)
Eterm* hp;
Uint arity;
Eterm res;
Sint ix;
Sint ix, c1, c2;

if (is_not_tuple(BIF_ARG_2) || is_not_small(BIF_ARG_1)) {
BIF_ERROR(BIF_P, BADARG);
Expand All @@ -2561,14 +2561,12 @@ BIF_RETTYPE insert_element_3(BIF_ALIST_3)
res = make_tuple(hp);
*hp = make_arityval(arity + 1);

ix--;
arity -= ix;

while (ix--) { *++hp = *++ptr; }
c1 = ix - 1;
c2 = arity - ix + 1;

while (c1--) { *++hp = *++ptr; }
*++hp = BIF_ARG_3;

while(arity--) { *++hp = *++ptr; }
while (c2--) { *++hp = *++ptr; }

BIF_RET(res);
}
Expand All @@ -2579,7 +2577,7 @@ BIF_RETTYPE delete_element_2(BIF_ALIST_3)
Eterm* hp;
Uint arity;
Eterm res;
Sint ix;
Sint ix, c1, c2;

if (is_not_tuple(BIF_ARG_2) || is_not_small(BIF_ARG_1)) {
BIF_ERROR(BIF_P, BADARG);
Expand All @@ -2597,14 +2595,12 @@ BIF_RETTYPE delete_element_2(BIF_ALIST_3)
res = make_tuple(hp);
*hp = make_arityval(arity - 1);

ix--;
arity -= ix;

while (ix--) { *++hp = *++ptr; }
c1 = ix - 1;
c2 = arity - ix;

while (c1--) { *++hp = *++ptr; }
++ptr;

while(arity--) { *++hp = *++ptr; }
while (c2--) { *++hp = *++ptr; }

BIF_RET(res);
}
Expand Down

0 comments on commit b3678dc

Please sign in to comment.