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

ruby-changes:45892

From: nobu <ko1@a...>
Date: Tue, 14 Mar 2017 12:42:47 +0900 (JST)
Subject: [ruby-changes:45892] nobu:r57965 (trunk): string.c: use rb_check_string_type

nobu	2017-03-14 12:42:43 +0900 (Tue, 14 Mar 2017)

  New Revision: 57965

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57965

  Log:
    string.c: use rb_check_string_type
    
    * string.c (rb_str_cmp_m): use rb_check_string_type for check and
      conversion, instead of calling the conversion method directly.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 57964)
+++ string.c	(revision 57965)
@@ -3181,19 +3181,11 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L3181
 rb_str_cmp_m(VALUE str1, VALUE str2)
 {
     int result;
-
-    if (!RB_TYPE_P(str2, T_STRING)) {
-	VALUE tmp = rb_check_funcall(str2, idTo_str, 0, 0);
-	if (RB_TYPE_P(tmp, T_STRING)) {
-	    result = rb_str_cmp(str1, tmp);
-	}
-	else {
-	    return rb_invcmp(str1, str2);
-	}
-    }
-    else {
-	result = rb_str_cmp(str1, str2);
+    VALUE s = rb_check_string_type(str2);
+    if (NIL_P(s)) {
+	return rb_invcmp(str1, str2);
     }
+    result = rb_str_cmp(str1, s);
     return INT2FIX(result);
 }
 

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

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