summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2021-06-17 11:29:28 -0700
committerAlan Wu <XrXr@users.noreply.github.com>2021-10-20 18:19:36 -0400
commit7d252186fe803aa5e1fa37c953609266a2d8ba1d (patch)
tree75a96ce2e12cc25c53c6d3fd88b0f2f2425afa1d /bootstraptest
parent8c68f112d8ec9f5a9a416fc69602855bf43c4dd6 (diff)
Simplify known class check for singletons
Singleton classes should only ever be attached to one object. This means that checking for the object should be the same as checking for the class. This should be slightly faster by avoiding one memory acccess as well as allowing us to skip checking if the receiver is a heap object. This will be most common for calling class methods.
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 129903bf9c..e15728fd98 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1153,3 +1153,34 @@ assert_equal '7', %q{
foo(5,2)
foo(5,2)
}
+
+# Call to object with singleton
+assert_equal '123', %q{
+ obj = Object.new
+ def obj.foo
+ 123
+ end
+
+ def foo(obj)
+ obj.foo()
+ end
+
+ foo(obj)
+ foo(obj)
+}
+
+# Call to singleton class
+assert_equal '123', %q{
+ class Foo
+ def self.foo
+ 123
+ end
+ end
+
+ def foo(obj)
+ obj.foo()
+ end
+
+ foo(Foo)
+ foo(Foo)
+}