ruby-changes:8562
From: yugui <ko1@a...>
Date: Mon, 3 Nov 2008 13:16:10 +0900 (JST)
Subject: [ruby-changes:8562] Ruby:r20096 (trunk, ruby_1_9_1): * array.c (rb_ary_take_first_or_last): renamed rb_ary_partial more
yugui 2008-11-03 13:13:04 +0900 (Mon, 03 Nov 2008) New Revision: 20096 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20096 Log: * array.c (rb_ary_take_first_or_last): renamed rb_ary_partial more appropriately. (ary_take_pos_flags): new enum. makes the fourth argument of rb_ary_take_first_or_last more descriptive. (rb_ary_partial): renamed rb_ary_partial0 more appropriately. takes a new parameter klass for what class to instanciate. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/array.c trunk/ChangeLog trunk/array.c Index: array.c =================================================================== --- array.c (revision 20095) +++ array.c (revision 20096) @@ -603,20 +603,20 @@ } static VALUE -ary_make_partial0(VALUE ary, long offset, long len) +ary_make_partial(VALUE ary, VALUE klass, long offset, long len) { assert(offset >= 0); assert(len >= 0); assert(offset+len <= RARRAY_LEN(ary)); if (len <= RARRAY_EMBED_LEN_MAX) { - VALUE result = ary_alloc(rb_obj_class(ary)); + VALUE result = ary_alloc(klass); MEMCPY(ARY_EMBED_PTR(result), RARRAY_PTR(ary) + offset, VALUE, len); ARY_SET_EMBED_LEN(result, len); return result; } else { - VALUE shared, result = ary_alloc(rb_obj_class(ary)); + VALUE shared, result = ary_alloc(klass); FL_UNSET_EMBED(result); shared = ary_make_shared(ary); @@ -630,8 +630,14 @@ } } +enum ary_take_pos_flags +{ + ARY_TAKE_FIRST = 0, + ARY_TAKE_LAST = 1 +}; + static VALUE -ary_make_partial(int argc, VALUE *argv, VALUE ary, int last) +ary_take_first_or_last(int argc, VALUE *argv, VALUE ary, enum ary_take_pos_flags last) { VALUE nv; long n; @@ -648,7 +654,7 @@ if (last) { offset = RARRAY_LEN(ary) - n; } - return ary_make_partial0(ary, offset, n); + return ary_make_partial(ary, rb_cArray, offset, n); } /* @@ -737,7 +743,7 @@ } rb_ary_modify_check(ary); - result = ary_make_partial(argc, argv, ary, Qtrue); + result = ary_take_first_or_last(argc, argv, ary, Qtrue); ARY_INCREASE_LEN(ary, -RARRAY_LEN(result)); return result; } @@ -799,7 +805,7 @@ } rb_ary_modify_check(ary); - result = ary_make_partial(argc, argv, ary, Qfalse); + result = ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST); n = RARRAY_LEN(result); if (ARY_SHARED_P(ary)) { ARY_INCREASE_PTR(ary, n); @@ -883,7 +889,7 @@ klass = rb_obj_class(ary); if (len == 0) return ary_new(klass, 0); - return ary_make_partial0(ary, beg, len); + return ary_make_partial(ary, klass, beg, len); } /* @@ -993,7 +999,7 @@ return RARRAY_PTR(ary)[0]; } else { - return ary_make_partial(argc, argv, ary, Qfalse); + return ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST); } } @@ -1018,7 +1024,7 @@ return RARRAY_PTR(ary)[RARRAY_LEN(ary)-1]; } else { - return ary_make_partial(argc, argv, ary, Qtrue); + return ary_take_first_or_last(argc, argv, ary, ARY_TAKE_LAST); } } Index: ChangeLog =================================================================== --- ChangeLog (revision 20095) +++ ChangeLog (revision 20096) @@ -1,3 +1,12 @@ +Mon Nov 3 13:01:13 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * array.c (rb_ary_take_first_or_last): renamed rb_ary_partial more + appropriately. + (ary_take_pos_flags): new enum. makes the fourth argument of + rb_ary_take_first_or_last more descriptive. + (rb_ary_partial): renamed rb_ary_partial0 more appropriately. + takes a new parameter klass for what class to instanciate. + Mon Nov 3 13:00:26 2008 Yuki Sonoda (Yugui) <yugui@y...> * range.c (rb_range_beg_len): rb_raise takes C values as arguments. Index: ruby_1_9_1/array.c =================================================================== --- ruby_1_9_1/array.c (revision 20095) +++ ruby_1_9_1/array.c (revision 20096) @@ -603,20 +603,20 @@ } static VALUE -ary_make_partial0(VALUE ary, long offset, long len) +ary_make_partial(VALUE ary, VALUE klass, long offset, long len) { assert(offset >= 0); assert(len >= 0); assert(offset+len <= RARRAY_LEN(ary)); if (len <= RARRAY_EMBED_LEN_MAX) { - VALUE result = ary_alloc(rb_obj_class(ary)); + VALUE result = ary_alloc(klass); MEMCPY(ARY_EMBED_PTR(result), RARRAY_PTR(ary) + offset, VALUE, len); ARY_SET_EMBED_LEN(result, len); return result; } else { - VALUE shared, result = ary_alloc(rb_obj_class(ary)); + VALUE shared, result = ary_alloc(klass); FL_UNSET_EMBED(result); shared = ary_make_shared(ary); @@ -630,8 +630,14 @@ } } +enum ary_take_pos_flags +{ + ARY_TAKE_FIRST = 0, + ARY_TAKE_LAST = 1 +}; + static VALUE -ary_make_partial(int argc, VALUE *argv, VALUE ary, int last) +ary_take_first_or_last(int argc, VALUE *argv, VALUE ary, enum ary_take_pos_flags last) { VALUE nv; long n; @@ -648,7 +654,7 @@ if (last) { offset = RARRAY_LEN(ary) - n; } - return ary_make_partial0(ary, offset, n); + return ary_make_partial(ary, rb_cArray, offset, n); } /* @@ -737,7 +743,7 @@ } rb_ary_modify_check(ary); - result = ary_make_partial(argc, argv, ary, Qtrue); + result = ary_take_first_or_last(argc, argv, ary, Qtrue); ARY_INCREASE_LEN(ary, -RARRAY_LEN(result)); return result; } @@ -799,7 +805,7 @@ } rb_ary_modify_check(ary); - result = ary_make_partial(argc, argv, ary, Qfalse); + result = ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST); n = RARRAY_LEN(result); if (ARY_SHARED_P(ary)) { ARY_INCREASE_PTR(ary, n); @@ -883,7 +889,7 @@ klass = rb_obj_class(ary); if (len == 0) return ary_new(klass, 0); - return ary_make_partial0(ary, beg, len); + return ary_make_partial(ary, klass, beg, len); } /* @@ -993,7 +999,7 @@ return RARRAY_PTR(ary)[0]; } else { - return ary_make_partial(argc, argv, ary, Qfalse); + return ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST); } } @@ -1018,7 +1024,7 @@ return RARRAY_PTR(ary)[RARRAY_LEN(ary)-1]; } else { - return ary_make_partial(argc, argv, ary, Qtrue); + return ary_take_first_or_last(argc, argv, ary, ARY_TAKE_LAST); } } Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20095) +++ ruby_1_9_1/ChangeLog (revision 20096) @@ -1,3 +1,12 @@ +Mon Nov 3 13:01:13 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * array.c (rb_ary_take_first_or_last): renamed rb_ary_partial more + appropriately. + (ary_take_pos_flags): new enum. makes the fourth argument of + rb_ary_take_first_or_last more descriptive. + (rb_ary_partial): renamed rb_ary_partial0 more appropriately. + takes a new parameter klass for what class to instanciate. + Mon Nov 3 13:00:26 2008 Yuki Sonoda (Yugui) <yugui@y...> * range.c (rb_range_beg_len): rb_raise takes C values as arguments. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/