mruby-string-ext: combine variable declaration with initialization

This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-11-05 08:23:36 +09:00
parent 7e2f20573c
commit 6bcd433214
+1 -2
View File
@@ -1644,14 +1644,13 @@ str_chars_ary(mrb_state *mrb, mrb_value self)
struct RString *s = mrb_str_ptr(self);
const unsigned char *p = (unsigned char*)RSTR_PTR(s);
const unsigned char *e = p + RSTR_LEN(s);
mrb_value result;
/* Estimate character count for array pre-allocation */
mrb_int estimated_chars = RSTR_LEN(s);
if (!RSTR_SINGLE_BYTE_P(s) && !RSTR_BINARY_P(s)) {
estimated_chars = estimated_chars / 2; /* rough estimate for UTF-8 */
}
result = mrb_ary_new_capa(mrb, estimated_chars);
mrb_value result = mrb_ary_new_capa(mrb, estimated_chars);
if (RSTR_SINGLE_BYTE_P(s) || RSTR_BINARY_P(s)) {
/* ASCII/Binary: each byte is a character */