summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-09-08 11:53:27 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-09-26 10:23:02 +0200
commit6ffc045a817fbdf04a6945d3c260b55b0fa1fd1e (patch)
treee830df0ad8e9d5ad4413d1008115699b703e215b /string.c
parent4a4c5028258e53f3395af29655a66bcef796fd73 (diff)
[EXPERIMENTAL] Make Symbol#to_s return a frozen String
* Always the same frozen String for a given Symbol. * Avoids extra allocations whenever calling Symbol#to_s. * See [Feature #16150]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2437
Diffstat (limited to 'string.c')
-rw-r--r--string.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/string.c b/string.c
index 367773f0f5..3f0e69689c 100644
--- a/string.c
+++ b/string.c
@@ -10869,7 +10869,8 @@ sym_inspect(VALUE sym)
* sym.id2name -> string
* sym.to_s -> string
*
- * Returns the name or string corresponding to <i>sym</i>.
+ * Returns a frozen string corresponding to <i>sym</i>.
+ * The returned String is always the same String instance for a given Symbol.
*
* :fred.id2name #=> "fred"
* :ginger.to_s #=> "ginger"
@@ -10879,7 +10880,7 @@ sym_inspect(VALUE sym)
VALUE
rb_sym_to_s(VALUE sym)
{
- return str_new_shared(rb_cString, rb_sym2str(sym));
+ return rb_sym2str(sym);
}