Commit 8e03810b

8e03810bbf69Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

feat: add String#sum

Returns the sum of all bytes in the string as an integer checksum.

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

Details

Commit
8e03810bbf69
Parent
80de18839213

spinel_codegen.rbmodifiedView file

@@ -11828,6 +11828,13 @@
1182811828 if mname == "succ" || mname == "next"
1182911829 return "sp_str_succ(" + rc + ")"
1183011830 end
11831+ if mname == "sum"
11832+ tmp = new_temp
11833+ itmp = new_temp
11834+ emit(" mrb_int " + tmp + " = 0;")
11835+ emit(" for (mrb_int " + itmp + " = 0; " + rc + "[" + itmp + "]; " + itmp + "++) " + tmp + " += (unsigned char)" + rc + "[" + itmp + "];")
11836+ return tmp
11837+ end
1183111838 if mname == "eql?"
1183211839 return "(strcmp(" + rc + ", " + compile_arg0(nid) + ") == 0)"
1183311840 end