Commit 2912f5b9

2912f5b95547Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 4 files · +1 added · ~3 modified

Description

Add String#getbyte/setbyte/bytesize, Integer#succ, String#dup→sp_String

  • getbyte(i): byte value at position (const char* and sp_String)
  • setbyte(i, byte): in-place byte modification (sp_String only)
  • bytesize: byte length (same as length for ASCII)
  • Integer#succ: n + 1
  • String#dup now returns mutable sp_String (correct Ruby semantics)
  • sp_String_setbyte helper in emit.c

ruby-xor benchmark: Spinel 0.02s vs CRuby 1.49s (75x faster) 67/67 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
2912f5b95547
Parent
31a53948d821

examples/bm_ruby_xor.rbaddedView file

1+# Adapted from yjit-bench ruby-xor
2+# XOR two strings byte-by-byte
3+
4+def xor_strings(a, b)
5+ len = a.bytesize
6+ result = a.dup
7+ i = 0
8+ while i < len
9+ result.setbyte(i, a.getbyte(i) ^ b.getbyte(i))
10+ i = i.succ
11+ end
12+ result
13+end
14+
15+a = "abcdefghijklmnop" * 100
16+b = "qrstuvwxyz012345" * 100
17+
18+n = 10000
19+i = 0
20+while i < n
21+ xor_strings(a, b)
22+ i += 1
23+end
24+
25+result = xor_strings(a, b)
26+puts result.bytesize
27+puts result.getbyte(0)
28+puts result.getbyte(1)