summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-18 03:45:23 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-18 03:45:23 +0000
commitb28b7933a832bed1426852d67fe5e6ace8eb8bef (patch)
tree8a63392aa890acc4bb8b6a5ffd2f6bbc56af4cf6 /array.c
parent76fd9b85d9ee675c179e1460b27ff978f0ed9158 (diff)
downloadruby-b28b7933a832bed1426852d67fe5e6ace8eb8bef.tar.gz
* process.c (proc_getpgrp): prohibit for $SAFE=2.
[ruby-dev:24899] * process.c (get_pid): ditto. [ruby-dev:24904] * process.c (get_ppid): ditto. * array.c (rb_ary_delete): defer rb_ary_modify() until actual modification. [ruby-dev:24901] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/array.c b/array.c
index 3e55ca4e3b..957a11f9f6 100644
--- a/array.c
+++ b/array.c
@@ -363,7 +363,6 @@ rb_ary_initialize(argc, argv, ary)
long len;
VALUE size, val;
- rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
RARRAY(ary)->len = 0;
if (rb_block_given_p()) {
@@ -387,6 +386,7 @@ rb_ary_initialize(argc, argv, ary)
if (len > 0 && len * (long)sizeof(VALUE) <= len) {
rb_raise(rb_eArgError, "array size too big");
}
+ rb_ary_modify(ary);
if (len > RARRAY(ary)->aux.capa) {
REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
RARRAY(ary)->aux.capa = len;
@@ -445,7 +445,6 @@ rb_ary_store(ary, idx, val)
long idx;
VALUE val;
{
- rb_ary_modify(ary);
if (idx < 0) {
idx += RARRAY(ary)->len;
if (idx < 0) {
@@ -454,6 +453,7 @@ rb_ary_store(ary, idx, val)
}
}
+ rb_ary_modify(ary);
if (idx >= RARRAY(ary)->aux.capa) {
long new_capa = RARRAY(ary)->aux.capa / 2;
@@ -1071,7 +1071,7 @@ rb_ary_to_ary(obj)
}
static void
-rb_ary_update(ary, beg, len, rpl)
+rb_ary_splice(ary, beg, len, rpl)
VALUE ary;
long beg, len;
VALUE rpl;
@@ -1172,7 +1172,7 @@ rb_ary_aset(argc, argv, ary)
long offset, beg, len;
if (argc == 3) {
- rb_ary_update(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
+ rb_ary_splice(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
return argv[2];
}
if (argc != 2) {
@@ -1184,7 +1184,7 @@ rb_ary_aset(argc, argv, ary)
}
if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */
- rb_ary_update(ary, beg, len, argv[1]);
+ rb_ary_splice(ary, beg, len, argv[1]);
return argv[1];
}
@@ -1226,7 +1226,7 @@ rb_ary_insert(argc, argv, ary)
}
if (argc == 1) return ary;
- rb_ary_update(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
+ rb_ary_splice(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
return ary;
}
@@ -1968,7 +1968,6 @@ rb_ary_delete(ary, item)
{
long i1, i2;
- rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
VALUE e = RARRAY(ary)->ptr[i1];
@@ -1985,6 +1984,7 @@ rb_ary_delete(ary, item)
return Qnil;
}
+ rb_ary_modify(ary);
if (RARRAY(ary)->len > i2) {
RARRAY(ary)->len = i2;
if (i2 * 2 < RARRAY(ary)->aux.capa &&
@@ -2005,13 +2005,13 @@ rb_ary_delete_at(ary, pos)
long i, len = RARRAY(ary)->len;
VALUE del;
- rb_ary_modify(ary);
if (pos >= len) return Qnil;
if (pos < 0) {
pos += len;
if (pos < 0) return Qnil;
}
+ rb_ary_modify(ary);
del = RARRAY(ary)->ptr[pos];
for (i = pos + 1; i < len; i++, pos++) {
RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
@@ -2076,7 +2076,6 @@ rb_ary_slice_bang(argc, argv, ary)
VALUE arg1, arg2;
long pos, len;
- rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
pos = NUM2LONG(arg1);
len = NUM2LONG(arg2);
@@ -2085,7 +2084,7 @@ rb_ary_slice_bang(argc, argv, ary)
pos = RARRAY(ary)->len + pos;
}
arg2 = rb_ary_subseq(ary, pos, len);
- rb_ary_update(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */
+ rb_ary_splice(ary, pos, len, Qundef); /* Qnil/rb_ary_new2(0) */
return arg2;
}
@@ -2457,7 +2456,7 @@ rb_ary_concat(x, y)
{
y = to_ary(y);
if (RARRAY(y)->len > 0) {
- rb_ary_update(x, RARRAY(x)->len, 0, y);
+ rb_ary_splice(x, RARRAY(x)->len, 0, y);
}
return x;
}
@@ -2873,8 +2872,6 @@ rb_ary_uniq_bang(ary)
VALUE hash, v, vv;
long i, j;
- rb_ary_modify(ary);
-
hash = ary_make_hash(ary, 0);
if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
@@ -3005,7 +3002,7 @@ flatten(ary, idx, ary2, memo)
rb_raise(rb_eArgError, "tried to flatten recursive array");
}
rb_ary_push(memo, id);
- rb_ary_update(ary, idx, 1, ary2);
+ rb_ary_splice(ary, idx, 1, ary2);
while (i < lim) {
VALUE tmp;
@@ -3043,7 +3040,6 @@ rb_ary_flatten_bang(ary)
int mod = 0;
VALUE memo = Qnil;
- rb_ary_modify(ary);
while (i<RARRAY(ary)->len) {
VALUE ary2 = RARRAY(ary)->ptr[i];
VALUE tmp;