Skip to content

Commit 186c8b5

Browse files
author
matz
committed
* 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
1 parent 09a4937 commit 186c8b5

File tree

9 files changed

+301
-83
lines changed

9 files changed

+301
-83
lines changed

ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
Tue Nov 27 02:15:25 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* marshal.c (w_float): must distinguish -0.0 from 0.0.
4+
15
Mon Nov 26 20:57:24 2001 Akinori MUSHA <knu@iDaemons.org>
26

37
* ext/Setup*, ext/syslog/*: import the "syslog" module from the
48
rough ruby project.
59

10+
Mon Nov 26 16:14:42 2001 K.Kosako <kosako@sofnec.co.jp>
11+
12+
* gc.c (gc_mark_all): tweak mark order for little bit better scan.
13+
14+
* gc.c (rb_gc_mark): ditto.
15+
16+
* gc.c (rb_gc): ditto.
17+
618
Mon Nov 26 16:54:59 2001 Usaku Nakamura <usa@ruby-lang.org>
719

820
* win32/win32.c (mypopen): fixed that mypclose() didn't really close
@@ -11,11 +23,21 @@ Mon Nov 26 16:54:59 2001 Usaku Nakamura <usa@ruby-lang.org>
1123
* win32/win32.c (CreateChild): set STARTF_USESTDHANDLES flag only
1224
when some handles are passed.
1325

26+
Mon Nov 26 16:31:28 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
27+
28+
* enum.c (sort_by_i): slight performance boost.
29+
1430
Sun Nov 25 21:02:18 2001 Usaku Nakamura <usa@ruby-lang.org>
1531

1632
* parse.y (str_extend): change types of second and third arguments
1733
from char to int.
1834

35+
Thu Nov 22 20:15:28 2001 TAMURA Takashi <sheepman@tcn.zaq.ne.jp>
36+
37+
* gc.c (gc_mark_rest): should call gc_mark_children(), not gc_mark().
38+
39+
* gc.c (rb_gc_mark): may cause infinite looop.
40+
1941
Thu Nov 22 00:28:13 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
2042

2143
* parse.y (str_extend): should check nesting parentheses in #{}.

array.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,26 @@ rb_ary_sort(ary)
10861086
return ary;
10871087
}
10881088

1089+
static VALUE
1090+
sort_inplace(ary)
1091+
VALUE ary;
1092+
{
1093+
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),sort_2);
1094+
return ary;
1095+
}
1096+
1097+
VALUE
1098+
rb_ary_sort_inplace(ary)
1099+
VALUE ary;
1100+
{
1101+
rb_ary_modify(ary);
1102+
if (RARRAY(ary)->len <= 1) return ary;
1103+
1104+
FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
1105+
rb_ensure(sort_inplace, ary, sort_unlock, ary);
1106+
return ary;
1107+
}
1108+
10891109
static VALUE
10901110
rb_ary_collect(ary)
10911111
VALUE ary;
@@ -1493,7 +1513,9 @@ rb_ary_cmp(ary, ary2)
14931513
{
14941514
long i, len;
14951515

1496-
ary2 = to_ary(ary2);
1516+
if (TYPE(ary2) != T_ARRAY) {
1517+
ary2 = to_ary(ary2);
1518+
}
14971519
len = RARRAY(ary)->len;
14981520
if (len > RARRAY(ary2)->len) {
14991521
len = RARRAY(ary2)->len;

enum.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,23 @@ sort_by_i(i, memo)
208208
VALUE i;
209209
NODE *memo;
210210
{
211-
VALUE e = rb_ary_new3(3, rb_yield(i), INT2NUM(memo->u3.cnt), i);
211+
VALUE v, e;
212+
213+
v = rb_yield(i);
214+
if (TYPE(v) == T_ARRAY) {
215+
int j, len = RARRAY(v)->len;
216+
217+
e = rb_ary_new2(len+2);
218+
for (j=0; j<len; j++) {
219+
RARRAY(e)->ptr[j] = RARRAY(v)->ptr[j];
220+
}
221+
RARRAY(e)->ptr[j++] = INT2NUM(memo->u3.cnt);
222+
RARRAY(e)->ptr[j] = i;
223+
RARRAY(e)->len = len + 2;
224+
}
225+
else {
226+
e = rb_ary_new3(3, v, INT2NUM(memo->u3.cnt), i);
227+
}
212228
rb_ary_push(memo->u1.value, e);
213229
memo->u3.cnt++;
214230
return Qnil;
@@ -225,16 +241,16 @@ static VALUE
225241
enum_sort_by(obj)
226242
VALUE obj;
227243
{
228-
VALUE ary = rb_ary_new();
244+
VALUE ary = rb_ary_new2(2000);
229245
NODE *memo = rb_node_newnode(NODE_MEMO, ary, 0, 0);
230246
long i;
231247

232248
rb_iterate(rb_each, obj, sort_by_i, (VALUE)memo);
233249
rb_gc_force_recycle((VALUE)memo);
234-
rb_iterate(rb_ary_sort_bang, ary, sort_by_sort_body, 0);
250+
rb_ary_sort_inplace(ary);
235251
for (i=0; i<RARRAY(ary)->len; i++) {
236252
VALUE e = RARRAY(ary)->ptr[i];
237-
RARRAY(ary)->ptr[i] = rb_ary_entry(e, 2);
253+
RARRAY(ary)->ptr[i] = RARRAY(e)->ptr[2];
238254
}
239255

240256
return ary;

eval.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7614,6 +7614,9 @@ rb_thread_schedule()
76147614
copy_fds(&exceptfds, &th->exceptfds, th->fd);
76157615
if (max < th->fd) max = th->fd;
76167616
need_select = 1;
7617+
if (th->wait_for & WAIT_TIME) {
7618+
need_select = 2;
7619+
}
76177620
th->select_value = 0;
76187621
}
76197622
if (th->wait_for & WAIT_TIME) {
@@ -7673,6 +7676,18 @@ rb_thread_schedule()
76737676
}
76747677
END_FOREACH_FROM(curr, th);
76757678
}
7679+
if (n == 0 && need_select == 2) {
7680+
if (now < 0.0) now = timeofday();
7681+
FOREACH_THREAD_FROM(curr, th) {
7682+
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay < now) {
7683+
th->status = THREAD_RUNNABLE;
7684+
th->wait_for = 0;
7685+
th->select_value = 0;
7686+
found = 1;
7687+
}
7688+
}
7689+
END_FOREACH_FROM(curr, th);
7690+
}
76767691
if (n > 0) {
76777692
now = -1.0;
76787693
/* Some descriptors are ready.

ext/pty/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
if /mswin32|mingw/ !~ RUBY_PLATFORM
44
have_header("sys/stropts.h")
55
have_func("setresuid")
6-
$CFLAGS << "-DHAVE_DEV_PTMX" if /cygwin/ === RUBY_PLATFORM
76
have_header("libutil.h")
87
have_header("pty.h")
98
have_library("util", "openpty")
109
if have_func("openpty") or
1110
have_func("_getpty") or
11+
have_func("ptsname") or
1212
have_func("ioctl")
1313
create_makefile('pty')
1414
end

ext/pty/pty.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ getDevice(master,slave)
349349
int i,j;
350350
char MasterName[DEVICELEN];
351351

352-
#ifdef HAVE_DEV_PTMX
352+
#ifdef HAVE_PTSNAME
353353
char *pn;
354354
void (*s)();
355355

@@ -364,15 +364,15 @@ getDevice(master,slave)
364364
if(unlockpt(i) != -1) {
365365
if((pn = ptsname(i)) != NULL) {
366366
if((j = open(pn, O_RDWR, 0)) != -1) {
367-
#if defined I_PUSH
367+
#if defined I_PUSH && !defined linux
368368
if(ioctl(j, I_PUSH, "ptem") != -1) {
369369
if(ioctl(j, I_PUSH, "ldterm") != -1) {
370370
#endif
371371
*master = i;
372372
*slave = j;
373373
strcpy(SlaveName, pn);
374374
return;
375-
#if defined I_PUSH
375+
#if defined I_PUSH && !defined linux
376376
}
377377
}
378378
#endif
@@ -385,10 +385,10 @@ getDevice(master,slave)
385385
rb_raise(rb_eRuntimeError, "Cannot get Master/Slave device");
386386
#else
387387
for (p = deviceNo; *p != NULL; p++) {
388-
sprintf(MasterName ,MasterDevice,*p);
388+
sprintf(MasterName,MasterDevice,*p);
389389
if ((i = open(MasterName,O_RDWR,0)) >= 0) {
390390
*master = i;
391-
sprintf(SlaveName ,SlaveDevice,*p);
391+
sprintf(SlaveName,SlaveDevice,*p);
392392
if ((j = open(SlaveName,O_RDWR,0)) >= 0) {
393393
*slave = j;
394394
chown(SlaveName, getuid(), getgid());

gc.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -427,26 +427,23 @@ init_mark_stack()
427427

428428
#define MARK_STACK_EMPTY (mark_stack_ptr == mark_stack)
429429

430-
static int mark_all;
431-
432430
static void rb_gc_mark_children(VALUE ptr);
431+
433432
static void
434433
gc_mark_all()
435434
{
436435
RVALUE *p, *pend;
437436
int i;
438-
mark_all = 0;
439-
while(!mark_all){
440-
mark_all = 1;
441-
for (i = 0; i < heaps_used; i++) {
442-
p = heaps[i]; pend = p + heaps_limits[i];
443-
while (p < pend) {
444-
if ((p->as.basic.flags & FL_MARK) &&
445-
(p->as.basic.flags != FL_MARK)) {
446-
rb_gc_mark_children((VALUE)p);
447-
}
448-
p++;
437+
438+
init_mark_stack();
439+
for (i = 0; i < heaps_used; i++) {
440+
p = heaps[i]; pend = p + heaps_limits[i];
441+
while (p < pend) {
442+
if ((p->as.basic.flags & FL_MARK) &&
443+
(p->as.basic.flags != FL_MARK)) {
444+
rb_gc_mark_children((VALUE)p);
449445
}
446+
p++;
450447
}
451448
}
452449
}
@@ -464,7 +461,7 @@ gc_mark_rest()
464461

465462
while(p != tmp_arry){
466463
p--;
467-
rb_gc_mark(*p);
464+
rb_gc_mark_children(*p);
468465
}
469466
}
470467

@@ -565,32 +562,28 @@ void
565562
rb_gc_mark(ptr)
566563
VALUE ptr;
567564
{
565+
int ret;
568566
register RVALUE *obj = RANY(ptr);
569567

570568
if (rb_special_const_p(ptr)) return; /* special const not marked */
571569
if (obj->as.basic.flags == 0) return; /* free cell */
572570
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
573571

574-
if (!mark_stack_overflow){
575-
int ret;
576-
CHECK_STACK(ret);
577-
if (ret) {
572+
obj->as.basic.flags |= FL_MARK;
573+
574+
CHECK_STACK(ret);
575+
if (ret) {
576+
if (!mark_stack_overflow) {
578577
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
579578
*mark_stack_ptr = ptr;
580-
mark_stack_ptr++;
581-
return;
582-
}else{
579+
mark_stack_ptr++;
580+
}
581+
else {
583582
mark_stack_overflow = 1;
584583
}
585584
}
586585
}
587-
588-
obj->as.basic.flags |= FL_MARK;
589-
590-
if (mark_stack_overflow){
591-
mark_all &= 0;
592-
return;
593-
}else{
586+
else {
594587
rb_gc_mark_children(ptr);
595588
}
596589
}
@@ -1175,8 +1168,8 @@ rb_gc()
11751168
while (!MARK_STACK_EMPTY){
11761169
if (mark_stack_overflow){
11771170
gc_mark_all();
1178-
break;
1179-
}else{
1171+
}
1172+
else {
11801173
gc_mark_rest();
11811174
}
11821175
}

0 commit comments

Comments
 (0)