Skip to content

Commit

Permalink
* enum.c (enum_sort_by): use rb_ary_resize.
Browse files Browse the repository at this point in the history
  (ary_cutoff): removed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
akr committed Jan 8, 2011
1 parent 8eec9c9 commit 113f27b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Sat Jan 8 21:47:26 2011 Tanaka Akira <[email protected]>

* enum.c (enum_sort_by): use rb_ary_resize.
(ary_cutoff): removed.

Sat Jan 8 21:24:17 2011 Tanaka Akira <[email protected]>

* pack.c (swapf): compilation condition simplified.
Expand Down
17 changes: 2 additions & 15 deletions enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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:
* enum.sort_by {| obj | block } -> array
Expand Down Expand Up @@ -918,7 +905,7 @@ enum_sort_by(VALUE obj)
rb_ary_store(data.buf, SORT_BY_BUFSIZE*2-1, Qnil);
rb_block_call(obj, id_each, 0, 0, sort_by_i, (VALUE)&data);
if (data.n) {
ary_cutoff(data.buf, data.n*2);
rb_ary_resize(data.buf, data.n*2);
rb_ary_concat(ary, data.buf);
}
if (RARRAY_LEN(ary) > 2) {
Expand All @@ -931,7 +918,7 @@ enum_sort_by(VALUE obj)
for (i=1; i<RARRAY_LEN(ary); i+=2) {
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;
OBJ_INFECT(ary, obj);

Expand Down

0 comments on commit 113f27b

Please sign in to comment.