From f9806460e92d11824478eb8125f450b811dc3786 Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 7 Nov 2015 03:18:58 +0000 Subject: [PATCH] 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ string.c | 17 +++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ba77afa47..4693463b4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sat Nov 7 12:18:05 2015 Eric Wong + + * 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 * thread.c (rb_cThreadShield): make static diff --git a/string.c b/string.c index 3a0089669c..d834754743 100644 --- a/string.c +++ b/string.c @@ -17,6 +17,7 @@ #include "probes.h" #include "gc.h" #include +#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) } } -static ID id_to_s; - VALUE rb_obj_as_string(VALUE obj) { @@ -1237,7 +1236,7 @@ rb_obj_as_string(VALUE obj) 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) { 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) 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) 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 excl, int (*each)(VALUE, VALUE), VALUE a } } 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 str) 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) 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);