mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user