зеркало из https://github.com/github/ruby.git
array.c: refactoring of rb_ary_delete_same()
* array.c (ary_resize_smaller): new function to resize array. * array.c (rb_ary_delete): refactoring to extract a function. * array.c (rb_ary_delete_same): refactoring. It renames function, reduces duplicated code and removes unused code. * gc.c (wmap_final_func): follow the above change. * internal.h (rb_ary_delete_same): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
0012b0abd7
Коммит
56132b1346
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Sun Nov 25 22:34:00 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||
|
||||
* array.c (ary_resize_smaller): new function to resize array.
|
||||
|
||||
* array.c (rb_ary_delete): refactoring to extract a function.
|
||||
|
||||
* array.c (rb_ary_delete_same): refactoring.
|
||||
It renames function, reduces duplicated code and removes unused
|
||||
code.
|
||||
|
||||
* gc.c (wmap_final_func): follow the above change.
|
||||
|
||||
* internal.h (rb_ary_delete_same): ditto.
|
||||
|
||||
Sun Nov 25 22:27:33 2012 Benoit Daloze <eregontp@gmail.com>
|
||||
|
||||
* array.c: fixes for the updated documentation in r35858:
|
||||
|
|
41
array.c
41
array.c
|
@ -2720,6 +2720,19 @@ rb_ary_keep_if(VALUE ary)
|
|||
return ary;
|
||||
}
|
||||
|
||||
static void
|
||||
ary_resize_smaller(VALUE ary, long len)
|
||||
{
|
||||
rb_ary_modify(ary);
|
||||
if (RARRAY_LEN(ary) > len) {
|
||||
ARY_SET_LEN(ary, len);
|
||||
if (len * 2 < ARY_CAPA(ary) &&
|
||||
ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
|
||||
ary_resize_capa(ary, len * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ary.delete(obj) -> obj or nil
|
||||
|
@ -2765,29 +2778,20 @@ rb_ary_delete(VALUE ary, VALUE item)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
rb_ary_modify(ary);
|
||||
if (RARRAY_LEN(ary) > i2) {
|
||||
ARY_SET_LEN(ary, i2);
|
||||
if (i2 * 2 < ARY_CAPA(ary) &&
|
||||
ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
|
||||
ary_resize_capa(ary, i2*2);
|
||||
}
|
||||
}
|
||||
ary_resize_smaller(ary, i2);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_ary_delete_same_obj(VALUE ary, VALUE item)
|
||||
void
|
||||
rb_ary_delete_same(VALUE ary, VALUE item)
|
||||
{
|
||||
VALUE v = item;
|
||||
long i1, i2;
|
||||
|
||||
for (i1 = i2 = 0; i1 < RARRAY_LEN(ary); i1++) {
|
||||
VALUE e = RARRAY_PTR(ary)[i1];
|
||||
|
||||
if (e == item) {
|
||||
v = e;
|
||||
continue;
|
||||
}
|
||||
if (i1 != i2) {
|
||||
|
@ -2796,19 +2800,10 @@ rb_ary_delete_same_obj(VALUE ary, VALUE item)
|
|||
i2++;
|
||||
}
|
||||
if (RARRAY_LEN(ary) == i2) {
|
||||
return Qnil;
|
||||
return;
|
||||
}
|
||||
|
||||
rb_ary_modify(ary);
|
||||
if (RARRAY_LEN(ary) > i2) {
|
||||
ARY_SET_LEN(ary, i2);
|
||||
if (i2 * 2 < ARY_CAPA(ary) &&
|
||||
ARY_CAPA(ary) > ARY_DEFAULT_SIZE) {
|
||||
ary_resize_capa(ary, i2*2);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
ary_resize_smaller(ary, i2);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
2
gc.c
2
gc.c
|
@ -3752,7 +3752,7 @@ wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
|
|||
VALUE wmap, ary;
|
||||
if (!existing) return ST_STOP;
|
||||
wmap = (VALUE)arg, ary = (VALUE)*value;
|
||||
rb_ary_delete_same_obj(ary, wmap);
|
||||
rb_ary_delete_same(ary, wmap);
|
||||
if (!RARRAY_LEN(ary)) return ST_DELETE;
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ struct vtm; /* defined by timev.h */
|
|||
VALUE rb_ary_last(int, VALUE *, VALUE);
|
||||
void rb_ary_set_len(VALUE, long);
|
||||
VALUE rb_ary_cat(VALUE, const VALUE *, long);
|
||||
VALUE rb_ary_delete_same_obj(VALUE, VALUE);
|
||||
void rb_ary_delete_same(VALUE, VALUE);
|
||||
|
||||
/* bignum.c */
|
||||
VALUE rb_big_fdiv(VALUE x, VALUE y);
|
||||
|
|
Загрузка…
Ссылка в новой задаче