dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] symbol.c (rb_id2str): eliminate branch to set class
Date: Fri,  3 Feb 2017 23:34:39 +0000	[thread overview]
Message-ID: <20170203233439.7288-1-e@80x24.org> (raw)

Since fstring table encompasses all strings in symbol table,
we may reuse the fstring table walk to set the class and
eliminate the branch in rb_id2str.

* string.c (Init_String): use rb_cString immediately after definition
* symbol.c (rb_id2str): eliminate branch to set class
---
 string.c |  5 ++---
 symbol.c | 10 +---------
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/string.c b/string.c
index 3a7113dcc0..394fa8d332 100644
--- a/string.c
+++ b/string.c
@@ -10036,6 +10036,8 @@ Init_String(void)
 #define rb_intern(str) rb_intern_const(str)
 
     rb_cString  = rb_define_class("String", rb_cObject);
+    assert(rb_vm_fstring_table());
+    st_foreach(rb_vm_fstring_table(), fstring_set_class_i, rb_cString);
     rb_include_module(rb_cString, rb_mComparable);
     rb_define_alloc_func(rb_cString, empty_str_alloc);
     rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
@@ -10215,7 +10217,4 @@ Init_String(void)
     rb_define_method(rb_cSymbol, "swapcase", sym_swapcase, -1);
 
     rb_define_method(rb_cSymbol, "encoding", sym_encoding, 0);
-
-    assert(rb_vm_fstring_table());
-    st_foreach(rb_vm_fstring_table(), fstring_set_class_i, rb_cString);
 }
diff --git a/symbol.c b/symbol.c
index facdb3ce24..f4516ebbe4 100644
--- a/symbol.c
+++ b/symbol.c
@@ -744,15 +744,7 @@ rb_sym2str(VALUE sym)
 VALUE
 rb_id2str(ID id)
 {
-    VALUE str;
-
-    if ((str = lookup_id_str(id)) != 0) {
-        if (RBASIC(str)->klass == 0)
-            RBASIC_SET_CLASS_RAW(str, rb_cString);
-	return str;
-    }
-
-    return 0;
+    return lookup_id_str(id);
 }
 
 const char *
-- 
EW


                 reply	other threads:[~2017-02-03 23:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170203233439.7288-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).