aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2013-04-04 17:53:56 +0200
committerErlang/OTP <[email protected]>2013-04-04 17:53:56 +0200
commitb3678dc3c0dbf0a3aa8c54e248e4579afa1d8c67 (patch)
tree586bcfc4d4a6194f883c9339743abf79bd499554
parentd0e476746a4ce505bceab5a504a4c3e8fc06797a (diff)
parent9b25088a6f1494d4ff6cd39653dba155d6639f5d (diff)
downloadotp-b3678dc3c0dbf0a3aa8c54e248e4579afa1d8c67.tar.gz
otp-b3678dc3c0dbf0a3aa8c54e248e4579afa1d8c67.tar.bz2
otp-b3678dc3c0dbf0a3aa8c54e248e4579afa1d8c67.zip
Merge branch 'egil/r16/fix-delete_element/OTP-10932' into maint-r16
* egil/r16/fix-delete_element/OTP-10932: erts: Refactor erlang:insert_element/3 for clarity erts: Fix copy error in erlang:delete_element/2
-rw-r--r--erts/emulator/beam/bif.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index 9c438679ea..ff237b6a78 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -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);
@@ -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);
}
@@ -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);
@@ -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);
}