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

ruby-changes:40398

From: normal <ko1@a...>
Date: Sat, 7 Nov 2015 21:53:01 +0900 (JST)
Subject: [ruby-changes:40398] normal:r52479 (trunk): string.c: use predefined IDs for minor bloat reduction

normal	2015-11-07 12:18:58 +0900 (Sat, 07 Nov 2015)

  New Revision: 52479

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

  Log:
    string.c: use predefined IDs for minor bloat reduction
    
    * string.c (id_to_s): remove redundant variable
      (rb_obj_as_string): trade id_to_s for idTo_s
      (rb_str_equal): replace rb_intern(...) with pre-defined ID
      (rb_str_cmp_m): ditto
      (rb_str_match): ditto
      (str_upto_each): ditto
      (rb_str_sum): ditto
      (Init_String): remove id_to_s initialization
    
    This leads to a minor size reduction on my x86 (32-bit) system:
    
       text	   data	    bss	    dec	    hex	filename
     129373	      8	     32	 129413	  1f985	string.o-orig
     129082	      8	      8	 129098	  1f84a	string.o

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52478)
+++ ChangeLog	(revision 52479)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov  7 12:18:05 2015  Eric Wong  <e@8...>
+
+	* string.c (id_to_s): remove redundant variable
+	  (rb_obj_as_string): trade id_to_s for idTo_s
+	  (rb_str_equal): replace rb_intern(...) with pre-defined ID
+	  (rb_str_cmp_m): ditto
+	  (rb_str_match): ditto
+	  (str_upto_each): ditto
+	  (rb_str_sum): ditto
+	  (Init_String): remove id_to_s initialization
+
 Sat Nov  7 11:40:05 2015  Eric Wong  <e@8...>
 
 	* thread.c (rb_cThreadShield): make static
Index: string.c
===================================================================
--- string.c	(revision 52478)
+++ string.c	(revision 52479)
@@ -17,6 +17,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L17
 #include "probes.h"
 #include "gc.h"
 #include <assert.h>
+#include "id.h"
 
 #define BEG(no) (regs->beg[(no)])
 #define END(no) (regs->end[(no)])
@@ -1227,8 +1228,6 @@ str_shared_replace(VALUE str, VALUE str2 https://github.com/ruby/ruby/blob/trunk/string.c#L1228
     }
 }
 
-static ID id_to_s;
-
 VALUE
 rb_obj_as_string(VALUE obj)
 {
@@ -1237,7 +1236,7 @@ rb_obj_as_string(VALUE obj) https://github.com/ruby/ruby/blob/trunk/string.c#L1236
     if (RB_TYPE_P(obj, T_STRING)) {
 	return obj;
     }
-    str = rb_funcall(obj, id_to_s, 0);
+    str = rb_funcall(obj, idTo_s, 0);
     if (!RB_TYPE_P(str, T_STRING))
 	return rb_any_to_s(obj);
     OBJ_INFECT(str, obj);
@@ -2761,7 +2760,7 @@ rb_str_equal(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2760
 {
     if (str1 == str2) return Qtrue;
     if (!RB_TYPE_P(str2, T_STRING)) {
-	if (!rb_respond_to(str2, rb_intern("to_str"))) {
+	if (!rb_respond_to(str2, idTo_str)) {
 	    return Qfalse;
 	}
 	return rb_equal(str2, str1);
@@ -2816,7 +2815,7 @@ rb_str_cmp_m(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2815
     int result;
 
     if (!RB_TYPE_P(str2, T_STRING)) {
-	VALUE tmp = rb_check_funcall(str2, rb_intern("to_str"), 0, 0);
+	VALUE tmp = rb_check_funcall(str2, idTo_str, 0, 0);
 	if (RB_TYPE_P(tmp, T_STRING)) {
 	    result = rb_str_cmp(str1, tmp);
 	}
@@ -3219,7 +3218,7 @@ rb_str_match(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/string.c#L3218
 
       generic:
       default:
-	return rb_funcall(y, rb_intern("=~"), 1, x);
+	return rb_funcall(y, idEqTilde, 1, x);
     }
 }
 
@@ -3699,7 +3698,7 @@ str_upto_each(VALUE beg, VALUE end, int https://github.com/ruby/ruby/blob/trunk/string.c#L3698
 	    }
 	}
 	else {
-	    ID op = excl ? '<' : rb_intern("<=");
+	    ID op = excl ? '<' : idLE;
 	    VALUE args[2], fmt = rb_obj_freeze(rb_usascii_str_new_cstr("%.*d"));
 
 	    args[0] = INT2FIX(width);
@@ -8044,7 +8043,7 @@ rb_str_sum(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L8043
                 sum = rb_funcall(sum, '+', 1, LONG2FIX(sum0));
             }
 
-            mod = rb_funcall(INT2FIX(1), rb_intern("<<"), 1, INT2FIX(bits));
+            mod = rb_funcall(INT2FIX(1), idLTLT, 1, INT2FIX(bits));
             mod = rb_funcall(mod, '-', 1, INT2FIX(1));
             sum = rb_funcall(sum, '&', 1, mod);
         }
@@ -9368,8 +9367,6 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L9367
     rb_define_method(rb_cString, "valid_encoding?", rb_str_valid_encoding_p, 0);
     rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
 
-    id_to_s = rb_intern("to_s");
-
     rb_fs = Qnil;
     rb_define_variable("$;", &rb_fs);
     rb_define_variable("$-F", &rb_fs);

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

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