Commit 3244e074
3244e074f44fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
feat: add String#getbyte, setbyte, bytesize support
- getbyte returns byte value at position as integer
- setbyte mutates string in-place (works on dup'd strings)
- bytesize returns string length in bytes
- Fixes bm_ruby_xor benchmark
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 3244e074f44f
- Parent
- 69b4523884c4
spinel_codegen.rbmodifiedView file
@@ -1130,6 +1130,15 @@
11301130
if mname == "succ"11311131
return "int"11321132
end1133+
if mname == "getbyte"1134+
return "int"1135+
end1136+
if mname == "bytesize"1137+
return "int"1138+
end1139+
if mname == "setbyte"1140+
return "int"1141+
end11331142
if mname == "__method__"11341143
return "string"11351144
end@@ -7776,6 +7785,22 @@
77767785
if mname == "dup"77777786
return "sp_str_dup(" + rc + ")"77787787
end7788+
if mname == "getbyte"7789+
return "((mrb_int)(unsigned char)(" + rc + ")[" + compile_arg0(nid) + "])"7790+
end7791+
if mname == "setbyte"7792+
args_id = @nd_arguments[nid]7793+
if args_id >= 07794+
a = get_args(args_id)7795+
if a.length >= 27796+
return "(((char*)" + rc + ")[" + compile_expr(a[0]) + "] = (char)" + compile_expr(a[1]) + ", 0)"7797+
end7798+
end7799+
return "0"7800+
end7801+
if mname == "bytesize"7802+
return "(mrb_int)strlen(" + rc + ")"7803+
end77797804
if mname == "to_s"77807805
return rc77817806
end