From 62e5fa173788a443ad230eb379905515cad04a87 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 15 May 2009 08:35:35 +0000 Subject: [PATCH] * array.c (rb_ary_shift, rb_ary_shift_m): clears unused elements. [ruby-dev:38448] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9451d7b85c..a7747855f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri May 15 17:35:33 2009 Nobuyoshi Nakada + + * array.c (rb_ary_shift, rb_ary_shift_m): clears unused elements. + [ruby-dev:38448] + Fri May 15 15:15:12 2009 Nobuyoshi Nakada * variable.c (rb_autoload_load): checks if iv_tbl is valid. diff --git a/array.c b/array.c index 1f462f7899..1696171051 100644 --- a/array.c +++ b/array.c @@ -807,6 +807,9 @@ rb_ary_shift(VALUE ary) RARRAY_PTR(ary)[0] = Qnil; ary_make_shared(ary); } + else if (ARY_SHARED_NUM(ARY_SHARED(ary)) == 1) { + RARRAY_PTR(ary)[0] = Qnil; + } ARY_INCREASE_PTR(ary, 1); /* shift ptr */ ARY_INCREASE_LEN(ary, -1); @@ -848,6 +851,9 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary) result = ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST); n = RARRAY_LEN(result); if (ARY_SHARED_P(ary)) { + if (ARY_SHARED_NUM(ARY_SHARED(ary)) == 1) { + rb_mem_clear(RARRAY_PTR(ary), n); + } ARY_INCREASE_PTR(ary, n); } else {