summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-09-24 16:57:53 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:41 -0400
commita09adac2d76342fd4a0d97905b3397758689c817 (patch)
treeb36da7570712769a9c129c95df71761ab0d59104 /bootstraptest
parent79015926eb81ac93700146d42c343f568d3ddfbb (diff)
Add specialization for String#to_s on plain strings
When calling "to_s" on an instance of String, the method simply returns self. In this situation most of the work comes from setting up the method call. It turns out that both railsbench and liquid-render do this a lot. When generating code for opt_send_without_block, we already generate a known class guard, so we can detect when the receiver is a String instance. Since gen_send_cfunc() is also used for gen_invokesuper(), and gen_invokesuper() doesn't generate a known class guard, a new nullable parameter for specialized codegen function is added. Closes GH-245
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 73b87e17fd..91c39323e0 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -2038,3 +2038,38 @@ assert_equal '42', %q{
Ractor.new { A.foo }.take
}
+
+assert_equal '["plain", "special", "sub", "plain"]', %q{
+ def foo(arg)
+ arg.to_s
+ end
+
+ class Sub < String
+ end
+
+ special = String.new("special")
+ special.singleton_class
+
+ [
+ foo("plain"),
+ foo(special),
+ foo(Sub.new("sub")),
+ foo("plain")
+ ]
+}
+
+assert_equal '["sub", "sub"]', %q{
+ def foo(arg)
+ arg.to_s
+ end
+
+ class Sub < String
+ def to_s
+ super
+ end
+ end
+
+ sub = Sub.new("sub")
+
+ [foo(sub), foo(sub)]
+}