[前][次][番号順一覧][スレッド一覧]

ruby-changes:12784

From: ko1 <ko1@a...>
Date: Wed, 12 Aug 2009 14:55:28 +0900 (JST)
Subject: [ruby-changes:12784] Ruby:r24511 (trunk): * insns.def, vm.c, vm_insnhelper.c, vm_insnhelper.h: check

ko1	2009-08-12 14:55:06 +0900 (Wed, 12 Aug 2009)

  New Revision: 24511

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24511

  Log:
    * insns.def, vm.c, vm_insnhelper.c, vm_insnhelper.h: check
      definition of (classes)#=== for case/when optimization.
      Fix Bug #1376 [ruby-core:23190].
    * string.c (Init_String), bignum.c (Init_Bignum),
      numeric.c (Init_Numeric): define String#===, Symbol#===,
      Bignum#===, Fixnum#===, Float#=== as same as (classes)#==.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/insns.def
    trunk/numeric.c
    trunk/string.c
    trunk/vm.c
    trunk/vm_insnhelper.c
    trunk/vm_insnhelper.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24510)
+++ ChangeLog	(revision 24511)
@@ -1,3 +1,13 @@
+Wed Aug 12 Wed Aug 12 14:54:34 2009  Koichi Sasada  <ko1@a...>
+
+	* insns.def, vm.c, vm_insnhelper.c, vm_insnhelper.h: check
+	  definition of (classes)#=== for case/when optimization.
+	  Fix Bug #1376 [ruby-core:23190].
+
+	* string.c (Init_String), bignum.c (Init_Bignum),
+	  numeric.c (Init_Numeric): define String#===, Symbol#===,
+	  Bignum#===, Fixnum#===, Float#=== as same as (classes)#==.
+
 Wed Aug 12 14:14:42 2009  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (readdir_internal): free old temporary filename.
Index: insns.def
===================================================================
--- insns.def	(revision 24510)
+++ insns.def	(revision 24511)
@@ -1233,10 +1233,7 @@
 (..., VALUE key)
 () // inc += -1;
 {
-    if (0) {
-	/* TODO: if some === method is overrided */
-    }
-    else {
+    if (BASIC_OP_UNREDEFINED_P(BOP_EQQ)) {
 	VALUE val;
 	if (st_lookup(RHASH_TBL(hash), key, &val)) {
 	    JUMP(FIX2INT(val));
@@ -1245,6 +1242,20 @@
 	    JUMP(else_offset);
 	}
     }
+    else {
+	struct opt_case_dispatch_i_arg arg = {
+	    key, -1
+	};
+
+	st_foreach(RHASH_TBL(hash), opt_case_dispatch_i, &arg);
+
+	if (arg.label != -1) {
+	    JUMP(arg.label);
+	}
+	else {
+	    JUMP(else_offset);
+	}
+    }
 }
 
 /**
Index: string.c
===================================================================
--- string.c	(revision 24510)
+++ string.c	(revision 24511)
@@ -7418,6 +7418,7 @@
     rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
     rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
     rb_define_method(rb_cString, "==", rb_str_equal, 1);
+    rb_define_method(rb_cString, "===", rb_str_equal, 1);
     rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
     rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
     rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
@@ -7547,6 +7548,7 @@
     rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */
 
     rb_define_method(rb_cSymbol, "==", sym_equal, 1);
+    rb_define_method(rb_cSymbol, "===", sym_equal, 1);
     rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
     rb_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
     rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
Index: numeric.c
===================================================================
--- numeric.c	(revision 24510)
+++ numeric.c	(revision 24511)
@@ -3222,6 +3222,7 @@
     rb_define_method(rb_cFixnum, "magnitude", fix_abs, 0);
 
     rb_define_method(rb_cFixnum, "==", fix_equal, 1);
+    rb_define_method(rb_cFixnum, "===", fix_equal, 1);
     rb_define_method(rb_cFixnum, "<=>", fix_cmp, 1);
     rb_define_method(rb_cFixnum, ">",  fix_gt, 1);
     rb_define_method(rb_cFixnum, ">=", fix_ge, 1);
@@ -3275,6 +3276,7 @@
     rb_define_method(rb_cFloat, "divmod", flo_divmod, 1);
     rb_define_method(rb_cFloat, "**", flo_pow, 1);
     rb_define_method(rb_cFloat, "==", flo_eq, 1);
+    rb_define_method(rb_cFloat, "===", flo_eq, 1);
     rb_define_method(rb_cFloat, "<=>", flo_cmp, 1);
     rb_define_method(rb_cFloat, ">",  flo_gt, 1);
     rb_define_method(rb_cFloat, ">=", flo_ge, 1);
Index: vm.c
===================================================================
--- vm.c	(revision 24510)
+++ vm.c	(revision 24511)
@@ -968,6 +968,7 @@
     OP(DIV, DIV), (C(Fixnum), C(Float));
     OP(MOD, MOD), (C(Fixnum), C(Float));
     OP(Eq, EQ), (C(Fixnum), C(Float), C(String));
+    OP(Eqq, EQQ), (C(Fixnum), C(Bignum), C(Float), C(Symbol), C(String));
     OP(LT, LT), (C(Fixnum));
     OP(LE, LE), (C(Fixnum));
     OP(LTLT, LTLT), (C(String), C(Array));
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 24510)
+++ vm_insnhelper.c	(revision 24511)
@@ -1592,3 +1592,21 @@
 
     return val;
 }
+
+struct opt_case_dispatch_i_arg {
+    VALUE obj;
+    int label;
+};
+
+static int
+opt_case_dispatch_i(st_data_t key, st_data_t data, struct opt_case_dispatch_i_arg *arg)
+{
+    if (RTEST(rb_funcall((VALUE)key, idEqq, 1, arg->obj))) {
+	arg->label = FIX2INT((VALUE)data);
+	return ST_STOP;
+    }
+    else {
+	return ST_CONTINUE;
+    }
+}
+
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 24510)
+++ vm_insnhelper.h	(revision 24511)
@@ -41,6 +41,7 @@
   BOP_DIV,
   BOP_MOD,
   BOP_EQ,
+  BOP_EQQ,
   BOP_LT,
   BOP_LE,
   BOP_LTLT,
Index: bignum.c
===================================================================
--- bignum.c	(revision 24510)
+++ bignum.c	(revision 24511)
@@ -3253,6 +3253,7 @@
 
     rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1);
     rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
+    rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
     rb_define_method(rb_cBignum, "eql?", rb_big_eql, 1);
     rb_define_method(rb_cBignum, "hash", rb_big_hash, 0);
     rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]