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

ruby-changes:25985

From: nobu <ko1@a...>
Date: Fri, 30 Nov 2012 17:43:59 +0900 (JST)
Subject: [ruby-changes:25985] nobu:r38042 (trunk): string.c: always fixed value

nobu	2012-11-30 17:43:42 +0900 (Fri, 30 Nov 2012)

  New Revision: 38042

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

  Log:
    string.c: always fixed value
    
    * string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38041)
+++ ChangeLog	(revision 38042)
@@ -1,3 +1,15 @@
+Fri Nov 30 17:43:39 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
+
+	* string.c (rb_str_cmp_m): try to compare with to_str result if
+	  possible before calling <=> method.  [ruby-core:49279] [Bug #7342]
+
+	* string.c (rb_str_cmp_m): use rb_check_funcall instead of respond_to
+	  and call.
+
+	* string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
+
 Fri Nov 30 16:19:14 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_dump.c (rb_vm_bugreport): get rid of calling methods in sigsegv
Index: string.c
===================================================================
--- string.c	(revision 38041)
+++ string.c	(revision 38042)
@@ -2382,7 +2382,7 @@
 static VALUE
 rb_str_cmp_m(VALUE str1, VALUE str2)
 {
-    long result;
+    int result;
 
     if (!RB_TYPE_P(str2, T_STRING)) {
 	if (!rb_respond_to(str2, rb_intern("to_str"))) {
@@ -2395,16 +2395,13 @@
 	    VALUE tmp = rb_funcall(str2, rb_intern("<=>"), 1, str1);
 
 	    if (NIL_P(tmp)) return Qnil;
-	    if (!FIXNUM_P(tmp)) {
-		return rb_funcall(LONG2FIX(0), '-', 1, tmp);
-	    }
-	    result = -FIX2LONG(tmp);
+	    result = -rb_cmpint(tmp, str1, str2);
 	}
     }
     else {
 	result = rb_str_cmp(str1, str2);
     }
-    return LONG2NUM(result);
+    return INT2FIX(result);
 }
 
 /*
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 38041)
+++ test/ruby/test_string.rb	(revision 38042)
@@ -181,7 +181,7 @@
 
     class << o;remove_method :<=>;end
     def o.<=>(x); 2**100; end
-    assert_equal(-(2**100), "foo" <=> o)
+    assert_equal(-1, "foo" <=> o)
   end
 
   def test_EQUAL # '=='

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

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