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-xor2+
# XOR two strings byte-by-byte3+
4+
def xor_strings(a, b)5+
len = a.bytesize6+
result = a.dup7+
i = 08+
while i < len9+
result.setbyte(i, a.getbyte(i) ^ b.getbyte(i))10+
i = i.succ11+
end12+
result13+
end14+
15+
a = "abcdefghijklmnop" * 10016+
b = "qrstuvwxyz012345" * 10017+
18+
n = 1000019+
i = 020+
while i < n21+
xor_strings(a, b)22+
i += 123+
end24+
25+
result = xor_strings(a, b)26+
puts result.bytesize27+
puts result.getbyte(0)28+
puts result.getbyte(1)src/emit.cmodifiedView file
Loading diff…
src/expr.cmodifiedView file
Loading diff…
src/type.cmodifiedView file
Loading diff…