mruby-io/io.c: use RSTR_SET_LEN() instead of mrb_str_resize()

since the latter may shrink allocated buffer, and may cause repeated
allocations.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-01-03 15:49:19 +09:00
parent 1bc0be3e43
commit 99dffb6daf
+2 -2
View File
@@ -1010,7 +1010,7 @@ io_seek(mrb_state *mrb, mrb_value io)
{
mrb_value pos = io_sysseek(mrb, io);
mrb_value buf = io_buf(mrb, io);
mrb_str_resize(mrb, buf, 0);
RSTR_SET_LEN(RSTRING(buf), 0);
return pos;
}
@@ -1087,7 +1087,7 @@ io_write(mrb_state *mrb, mrb_value io)
/* move cursor */
n = lseek(fd, n - RSTRING_LEN(buf), SEEK_SET);
if (n == -1) mrb_sys_fail(mrb, "lseek(2)");
mrb_str_resize(mrb, buf, 0);
RSTR_SET_LEN(RSTRING(buf), 0);
}
if (mrb_get_argc(mrb) == 1) {