mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enum.c (enum_sort_by): use rb_ary_resize.
(ary_cutoff): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8eec9c9413
commit
113f27ba68
2 changed files with 7 additions and 15 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Jan 8 21:47:26 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* enum.c (enum_sort_by): use rb_ary_resize.
|
||||||
|
(ary_cutoff): removed.
|
||||||
|
|
||||||
Sat Jan 8 21:24:17 2011 Tanaka Akira <akr@fsij.org>
|
Sat Jan 8 21:24:17 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* pack.c (swapf): compilation condition simplified.
|
* pack.c (swapf): compilation condition simplified.
|
||||||
|
|
17
enum.c
17
enum.c
|
@ -812,19 +812,6 @@ sort_by_cmp(const void *ap, const void *bp, void *data)
|
||||||
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
|
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
ary_cutoff(VALUE ary, long len)
|
|
||||||
{
|
|
||||||
long i;
|
|
||||||
if (RBASIC(ary)->flags & RARRAY_EMBED_FLAG) {
|
|
||||||
for (i=RARRAY_LEN(ary)-len; 0<i; i--)
|
|
||||||
rb_ary_pop(ary);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
RARRAY(ary)->as.heap.len = len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* enum.sort_by {| obj | block } -> array
|
* enum.sort_by {| obj | block } -> array
|
||||||
|
@ -918,7 +905,7 @@ enum_sort_by(VALUE obj)
|
||||||
rb_ary_store(data.buf, SORT_BY_BUFSIZE*2-1, Qnil);
|
rb_ary_store(data.buf, SORT_BY_BUFSIZE*2-1, Qnil);
|
||||||
rb_block_call(obj, id_each, 0, 0, sort_by_i, (VALUE)&data);
|
rb_block_call(obj, id_each, 0, 0, sort_by_i, (VALUE)&data);
|
||||||
if (data.n) {
|
if (data.n) {
|
||||||
ary_cutoff(data.buf, data.n*2);
|
rb_ary_resize(data.buf, data.n*2);
|
||||||
rb_ary_concat(ary, data.buf);
|
rb_ary_concat(ary, data.buf);
|
||||||
}
|
}
|
||||||
if (RARRAY_LEN(ary) > 2) {
|
if (RARRAY_LEN(ary) > 2) {
|
||||||
|
@ -931,7 +918,7 @@ enum_sort_by(VALUE obj)
|
||||||
for (i=1; i<RARRAY_LEN(ary); i+=2) {
|
for (i=1; i<RARRAY_LEN(ary); i+=2) {
|
||||||
RARRAY_PTR(ary)[i/2] = RARRAY_PTR(ary)[i];
|
RARRAY_PTR(ary)[i/2] = RARRAY_PTR(ary)[i];
|
||||||
}
|
}
|
||||||
ary_cutoff(ary, RARRAY_LEN(ary)/2);
|
rb_ary_resize(ary, RARRAY_LEN(ary)/2);
|
||||||
RBASIC(ary)->klass = rb_cArray;
|
RBASIC(ary)->klass = rb_cArray;
|
||||||
OBJ_INFECT(ary, obj);
|
OBJ_INFECT(ary, obj);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue