1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_modify): should copy the internal buffer if the

modifying buffer is shared.

* array.c (ary_make_shared): make an internal buffer of an array
  to be shared.

* array.c (rb_ary_shift): avoid sliding an internal buffer by
  using shared buffer.

* array.c (rb_ary_subseq): avoid copying the buffer.

* parse.y (gettable): should freeze __LINE__ string.

* io.c (rb_io_puts): old behavoir restored.  rationale: a) if you
  want to call to_s for arrays, you can just call print a, "\n".
  b) to_s wastes memory if array (and sum of its contents) is
  huge.  c) now any object that has to_ary is treated as an array,
  using rb_check_convert_type().

* hash.c (rb_hash_initialize): now accepts a block to calculate
  the default value. [new]

* hash.c (rb_hash_aref): call "default" method to get the value
  corrensponding to the non existing key.

* hash.c (rb_hash_default): get the default value based on the
  block given to 'new'.  Now it takes an optinal "key" argument.
  "default" became the method to get the value for non existing
  key.  Users may override "default" method to change the hash
  behavior.

* hash.c (rb_hash_set_default): clear the flag if a block is given
  to 'new'

* object.c (Init_Object): undef Data.allocate, left Data.new.

* ext/curses/curses.c (window_scrollok): use RTEST().

* ext/curses/curses.c (window_idlok): ditto.

* ext/curses/curses.c (window_keypad): ditto.

* ext/curses/curses.c (window_idlok): idlok() may return void on
  some platforms; so don't use return value.

* ext/curses/curses.c (window_scrollok): ditto for consistency.

* ext/curses/curses.c: replace FIX2INT() by typechecking NUM2INT().

* parse.y (str_extend): should not process immature #$x and
  #@x interpolation, e.g #@#@ etc.

* enum.c (enum_sort_by): sort_by does not have to be stable always.

* enum.c (enum_sort_by): call qsort directly to gain performance.

* util.c (ruby_qsort): ruby_qsort(qs6) is now native thread safe.

* error.c (rb_sys_fail): it must be a bug if it's called when
  errno == 0.

* regex.c (WC2MBC1ST): should not pass through > 0x80 number in UTF-8.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-12-10 07:18:16 +00:00
parent 3493ea5c7a
commit 2f8d3bdc21
19 changed files with 651 additions and 334 deletions

47
enum.c
View file

@ -12,6 +12,7 @@
#include "ruby.h"
#include "node.h"
#include "util.h"
VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp;
@ -204,53 +205,41 @@ enum_sort(obj)
}
static VALUE
sort_by_i(i, memo)
VALUE i;
NODE *memo;
sort_by_i(i, ary)
VALUE i, ary;
{
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++;
e = rb_assoc_new(v, i);
rb_ary_push(ary, e);
return Qnil;
}
static VALUE
sort_by_sort_body(a)
VALUE a;
static int
sort_by_cmp(a, b)
VALUE *a, *b;
{
return rb_ary_cmp(RARRAY(a)->ptr[0], RARRAY(a)->ptr[1]);
VALUE retval;
retval = rb_funcall(RARRAY(*a)->ptr[0], id_cmp, 1, RARRAY(*b)->ptr[0]);
return rb_cmpint(retval);
}
static VALUE
enum_sort_by(obj)
VALUE obj;
{
VALUE ary = rb_ary_new2(2000);
NODE *memo = rb_node_newnode(NODE_MEMO, ary, 0, 0);
VALUE ary;
long i;
rb_iterate(rb_each, obj, sort_by_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
rb_ary_sort_inplace(ary);
ary = rb_ary_new2((TYPE(obj) == T_ARRAY) ? RARRAY(obj)->len : 2000);
rb_iterate(rb_each, obj, sort_by_i, ary);
if (RARRAY(ary)->len <= 1) return ary;
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp);
for (i=0; i<RARRAY(ary)->len; i++) {
VALUE e = RARRAY(ary)->ptr[i];
RARRAY(ary)->ptr[i] = RARRAY(e)->ptr[RARRAY(e)->len - 1];
RARRAY(ary)->ptr[i] = RARRAY(e)->ptr[1];
}
return ary;