From be1d214ace9068204a10160cd9a0e43d1ce9ecf7 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 11 Mar 1998 09:19:50 +0000 Subject: speed up patch 2 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++ numeric.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ parse.y | 57 +++++++++++++++++++++++++------ sample/rbc.rb | 33 +++++++++--------- 4 files changed, 175 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3ae662d6d..50f2ad8be0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,10 @@ Wed Mar 11 02:14:17 1998 Yukihiro Matsumoto * class.c (rb_define_method): disables superclass's overriding method by default. +Wed Mar 11 01:40:48 1998 MAEDA shugo + + * numeric.c (flo_gt,etc.): do not depend on `<=>', to handle NaN. + Tue Mar 10 00:03:24 1998 Yukihiro Matsumoto * ruby.c (load_file): understands multiple options in #! line. diff --git a/numeric.c b/numeric.c index d29a3fec3a..0266bbe023 100644 --- a/numeric.c +++ b/numeric.c @@ -403,6 +403,110 @@ flo_cmp(x, y) return INT2FIX(-1); } +static VALUE +flo_gt(x, y) + VALUE x, y; +{ + double a, b; + + a = RFLOAT(x)->value; + switch (TYPE(y)) { + case T_FIXNUM: + b = (double)FIX2INT(y); + break; + + case T_BIGNUM: + b = big2dbl(y); + break; + + case T_FLOAT: + b = RFLOAT(y)->value; + break; + + default: + return num_coerce_bin(x, y); + } + return (a > b)?TRUE:FALSE; +} + +static VALUE +flo_ge(x, y) + VALUE x, y; +{ + double a, b; + + a = RFLOAT(x)->value; + switch (TYPE(y)) { + case T_FIXNUM: + b = (double)FIX2INT(y); + break; + + case T_BIGNUM: + b = big2dbl(y); + break; + + case T_FLOAT: + b = RFLOAT(y)->value; + break; + + default: + return num_coerce_bin(x, y); + } + return (a >= b)?TRUE:FALSE; +} + +static VALUE +flo_lt(x, y) + VALUE x, y; +{ + double a, b; + + a = RFLOAT(x)->value; + switch (TYPE(y)) { + case T_FIXNUM: + b = (double)FIX2INT(y); + break; + + case T_BIGNUM: + b = big2dbl(y); + break; + + case T_FLOAT: + b = RFLOAT(y)->value; + break; + + default: + return num_coerce_bin(x, y); + } + return (a < b)?TRUE:FALSE; +} + +static VALUE +flo_le(x, y) + VALUE x, y; +{ + double a, b; + + a = RFLOAT(x)->value; + switch (TYPE(y)) { + case T_FIXNUM: + b = (double)FIX2INT(y); + break; + + case T_BIGNUM: + b = big2dbl(y); + break; + + case T_FLOAT: + b = RFLOAT(y)->value; + break; + + default: + return num_coerce_bin(x, y); + } + return (a <= b)?TRUE:FALSE; +} + static VALUE flo_eql(x, y) VALUE x, y; @@ -1161,6 +1265,10 @@ Init_Numeric() rb_define_method(cFloat, "**", flo_pow, 1); rb_define_method(cFloat, "==", flo_eq, 1); rb_define_method(cFloat, "<=>", flo_cmp, 1); + rb_define_method(cFloat, ">", flo_gt, 1); + rb_define_method(cFloat, ">=", flo_ge, 1); + rb_define_method(cFloat, "<", flo_lt, 1); + rb_define_method(cFloat, "<=", flo_le, 1); rb_define_method(cFloat, "eql?", flo_eql, 1); rb_define_method(cFloat, "hash", flo_hash, 0); rb_define_method(cFloat, "to_i", flo_to_i, 0); diff --git a/parse.y b/parse.y index 47c610a7ed..e3c3b799c8 100644 --- a/parse.y +++ b/parse.y @@ -531,8 +531,8 @@ op : DOT2 { $$ = DOT2; } | '%' { $$ = '%'; } | POW { $$ = POW; } | '~' { $$ = '~'; } - | UPLUS { $$ = UMINUS; } - | UMINUS { $$ = UPLUS; } + | UPLUS { $$ = UPLUS; } + | UMINUS { $$ = UMINUS; } | AREF { $$ = AREF; } | ASET { $$ = ASET; } | '`' { $$ = '`'; } @@ -3724,14 +3724,20 @@ local_push() static void local_pop() { - struct local_vars *local = lvtbl; + struct local_vars *local = lvtbl->prev; - lvtbl = local->prev; - if (local->tbl) { - local->tbl[0] = local->cnt; - if (!local->nofree) free(local->tbl); + if (lvtbl->tbl) { + if (!lvtbl->nofree) free(lvtbl->tbl); + else { + lvtbl->tbl[0] = lvtbl->cnt; +#if 1 + lvtbl->tbl[lvtbl->cnt+1] = local_cnt('_'); + lvtbl->tbl[lvtbl->cnt+2] = local_cnt('~'); +#endif + } } - free(local); + free(lvtbl); + lvtbl = local; } static ID* @@ -3753,13 +3759,12 @@ local_cnt(id) if (lvtbl->tbl[cnt] == id) return cnt-1; } - if (lvtbl->tbl == 0) { lvtbl->tbl = ALLOC_N(ID, 2); lvtbl->tbl[0] = 0; } else { - REALLOC_N(lvtbl->tbl, ID, lvtbl->cnt+2); + REALLOC_N(lvtbl->tbl, ID, lvtbl->cnt+4); } lvtbl->tbl[lvtbl->cnt+1] = id; @@ -3785,7 +3790,7 @@ top_local_init() local_push(); lvtbl->cnt = the_scope->local_tbl?the_scope->local_tbl[0]:0; if (lvtbl->cnt > 0) { - lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+1); + lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+3); MEMCPY(lvtbl->tbl, the_scope->local_tbl, ID, lvtbl->cnt+1); } else { @@ -3827,6 +3832,10 @@ top_local_setup() the_scope->local_vars = vars+1; memclear(the_scope->local_vars+i, len-i); } +#if 1 + local_cnt('_'); + local_cnt('~'); +#endif lvtbl->tbl[0] = len; if (the_scope->local_tbl && the_scope->local_vars[-1] == 0) { free(the_scope->local_tbl); @@ -4124,6 +4133,7 @@ special_local_set(c, val) { int cnt, max; +#if 0 if (the_scope->local_tbl) { for (cnt=1, max=the_scope->local_tbl[0]+1; cntlocal_tbl[cnt] == c) { @@ -4132,6 +4142,7 @@ special_local_set(c, val) } } } +#endif top_local_init(); cnt = local_cnt(c); top_local_setup(); @@ -4141,27 +4152,51 @@ special_local_set(c, val) VALUE backref_get() { +#if 1 + if (the_scope->local_tbl) { + return the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+2]]; + } + return Qnil; +#else return special_local_get('~'); +#endif } void backref_set(val) VALUE val; { +#if 1 + if (the_scope->local_tbl) { + the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+2]] = val; + } else +#endif special_local_set('~', val); } VALUE lastline_get() { +#if 1 + if (the_scope->local_tbl) { + return the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+1]]; + } + return Qnil; +#else VALUE v = special_local_get('_'); if (v == 1) return Qnil; /* $_ undefined */ return v; +#endif } void lastline_set(val) VALUE val; { +#if 1 + if (the_scope->local_tbl) { + the_scope->local_vars[the_scope->local_tbl[the_scope->local_tbl[0]+1]] = val; + } else +#endif special_local_set('_', val); } diff --git a/sample/rbc.rb b/sample/rbc.rb index e09dae6069..5dd2cf230d 100644 --- a/sample/rbc.rb +++ b/sample/rbc.rb @@ -2,8 +2,8 @@ # # rbc.rb - # $Release Version: 0.8 $ -# $Revision: 1.7 $ -# $Date: 1998/02/27 03:45:51 $ +# $Revision: 1.8 $ +# $Date: 1998/03/11 05:43:00 $ # by Keiju ISHITSUKA(Nippon Rational Inc.) # # -- @@ -23,7 +23,7 @@ # # 追加 private method: # exit, quit 終了する. -# inspect(sw = nil) インスペクトモードのトグル +# inspect_mode(sw = nil) インスペクトモードのトグル # trace_load(sw = nil) load/require時にrbcのfile読み込み機能を用 # いるモードのスイッチ(デフォルトはトレース # モード) @@ -33,7 +33,7 @@ require "e2mmap.rb" $stdout.sync = TRUE module BC_APPLICATION__ - RCS_ID='-$Id: rbc.rb,v 1.7 1998/02/27 03:45:51 keiju Exp keiju $-' + RCS_ID='-$Id: rbc.rb,v 1.8 1998/03/11 05:43:00 keiju Exp keiju $-' extend Exception2MessageMapper def_exception :UnrecognizedSwitch, "Unrecognized switch: %s" @@ -43,7 +43,7 @@ module BC_APPLICATION__ CONFIG[:USE_READLINE] = TRUE CONFIG[:LOAD_MODULES] = [] CONFIG[:INSPECT] = nil - CONFIG[:TRACE_LOAD] = TRUE + CONFIG[:TRACE_LOAD] = FALSE CONFIG[:RC] = TRUE CONFIG[:DEBUG] = FALSE @@ -831,25 +831,26 @@ module BC_APPLICATION__ module CONTEXT def _=(value) - @_ = value + CONFIG[:_] = value + eval "_=BC_APPLICATION__::CONFIG[:_]", CONFIG[:BIND] end - def _ - @_ - end +# def _ +# eval "_", CONFIG[:BIND] +# end def quit exit end def trace_load(opt = nil) - if opt - @Trace_require = opt + if !opt.nil? + CONFIG[:TRACE_LOAD] = opt else - @Trace_require = !@Trace_require + CONFIG[:TRACE_LOAD] = !CONFIG[:TRACE_LOAD] end - print "Switch to load/require #{unless @Trace_require; ' non';end} trace mode.\n" - if @Trace_require + print "Switch to load/require #{unless CONFIG[:TRACE_LOAD]; ' non';end} trace mode.\n" + if CONFIG[:TRACE_LOAD] eval %{ class << self alias load rbc_load @@ -864,7 +865,7 @@ module BC_APPLICATION__ end } end - @Trace_require + CONFIG[:TRACE_LOAD] end alias rbc_load_org load @@ -911,7 +912,7 @@ module BC_APPLICATION__ return false end - def inspect(opt = nil) + def inspect_mode(opt = nil) if opt CONFIG[:INSPECT] = opt else -- cgit v1.2.3