summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-27 10:00:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-27 10:00:35 +0000
commit186c8b592a8b5badfd42ff7295c5edb44ef1abdd (patch)
tree922c6ba9baaf7b140efadfb387c0a0780e544eb6 /enum.c
parent09a4937b2fcf883fa57af1dfa5d12f605f812970 (diff)
* marshal.c (w_float): must distinguish -0.0 from 0.0.
* gc.c (gc_mark_all): tweak mark order for little bit better scan. * gc.c (rb_gc_mark): ditto. * gc.c (rb_gc): ditto. * enum.c (sort_by_i): slight performance boost. * gc.c (gc_mark_rest): should call gc_mark_children(), not gc_mark(). * gc.c (rb_gc_mark): may cause infinite looop. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/enum.c b/enum.c
index af01645..fb72849 100644
--- a/enum.c
+++ b/enum.c
@@ -208,7 +208,23 @@ sort_by_i(i, memo)
VALUE i;
NODE *memo;
{
- VALUE e = rb_ary_new3(3, rb_yield(i), INT2NUM(memo->u3.cnt), i);
+ VALUE v, e;
+
+ v = rb_yield(i);
+ if (TYPE(v) == T_ARRAY) {
+ int j, len = RARRAY(v)->len;
+
+ e = rb_ary_new2(len+2);
+ for (j=0; j<len; j++) {
+ RARRAY(e)->ptr[j] = RARRAY(v)->ptr[j];
+ }
+ RARRAY(e)->ptr[j++] = INT2NUM(memo->u3.cnt);
+ RARRAY(e)->ptr[j] = i;
+ RARRAY(e)->len = len + 2;
+ }
+ else {
+ e = rb_ary_new3(3, v, INT2NUM(memo->u3.cnt), i);
+ }
rb_ary_push(memo->u1.value, e);
memo->u3.cnt++;
return Qnil;
@@ -225,16 +241,16 @@ static VALUE
enum_sort_by(obj)
VALUE obj;
{
- VALUE ary = rb_ary_new();
+ VALUE ary = rb_ary_new2(2000);
NODE *memo = rb_node_newnode(NODE_MEMO, ary, 0, 0);
long i;
rb_iterate(rb_each, obj, sort_by_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
- rb_iterate(rb_ary_sort_bang, ary, sort_by_sort_body, 0);
+ rb_ary_sort_inplace(ary);
for (i=0; i<RARRAY(ary)->len; i++) {
VALUE e = RARRAY(ary)->ptr[i];
- RARRAY(ary)->ptr[i] = rb_ary_entry(e, 2);
+ RARRAY(ary)->ptr[i] = RARRAY(e)->ptr[2];
}
return ary;