aboutsummaryrefslogtreecommitdiffstats
path: root/bootstraptest
diff options
context:
space:
mode:
authorIan Candy <ipc103@github.com>2023-09-07 23:15:24 -0400
committerGitHub <noreply@github.com>2023-09-07 23:15:24 -0400
commit78233e83529d7e3aee030cc6760f45104247fe51 (patch)
tree43afaa17df1bb263e94893c8d676eb88ba43a19a /bootstraptest
parent89edce432115c1bb46b2de0f4cd1e50c6e02ec41 (diff)
downloadruby-78233e83529d7e3aee030cc6760f45104247fe51.tar.gz
Add `String#getbyte` YJIT implementation (#8397)
* Add getbyte JIT implementation Adds an implementation for String#getbyte for YJIT, along with a bootstrap test. This should be helpful for pure Ruby implementations and to avoid unneeded allocations. Co-authored-by: John Hawthorn <jhawthorn@github.com> * Skip the getbyte test for RJIT for now --------- Co-authored-by: John Hawthorn <jhawthorn@github.com> Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 3c53641f91..82fd1e1376 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1832,6 +1832,24 @@ assert_equal 'true', %q{
jittable_method
}
+# test getbyte on string class
+assert_equal '[97, :nil, 97, :nil, :raised]', %q{
+ def getbyte(s, i)
+ byte = begin
+ s.getbyte(i)
+ rescue TypeError
+ :raised
+ end
+
+ byte || :nil
+ end
+
+ getbyte("a", 0)
+ getbyte("a", 0)
+
+ [getbyte("a", 0), getbyte("a", 1), getbyte("a", -1), getbyte("a", -2), getbyte("a", "a")]
+} unless defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # Not yet working on RJIT
+
# Test << operator on string subclass
assert_equal 'abab', %q{
class MyString < String; end