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 end
1133+ if mname == "getbyte"
1134+ return "int"
1135+ end
1136+ if mname == "bytesize"
1137+ return "int"
1138+ end
1139+ if mname == "setbyte"
1140+ return "int"
1141+ end
11331142 if mname == "__method__"
11341143 return "string"
11351144 end
@@ -7776,6 +7785,22 @@
77767785 if mname == "dup"
77777786 return "sp_str_dup(" + rc + ")"
77787787 end
7788+ if mname == "getbyte"
7789+ return "((mrb_int)(unsigned char)(" + rc + ")[" + compile_arg0(nid) + "])"
7790+ end
7791+ if mname == "setbyte"
7792+ args_id = @nd_arguments[nid]
7793+ if args_id >= 0
7794+ a = get_args(args_id)
7795+ if a.length >= 2
7796+ return "(((char*)" + rc + ")[" + compile_expr(a[0]) + "] = (char)" + compile_expr(a[1]) + ", 0)"
7797+ end
7798+ end
7799+ return "0"
7800+ end
7801+ if mname == "bytesize"
7802+ return "(mrb_int)strlen(" + rc + ")"
7803+ end
77797804 if mname == "to_s"
77807805 return rc
77817806 end