Skip to content

Commit 7a36808

Browse files
committed
Use rb_alloc_tmp_buffer in new_from_an_RString
1 parent c1f7039 commit 7a36808

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

internal/imemo.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,13 @@ RB_IMEMO_TMPBUF_PTR(VALUE v)
195195
static inline VALUE
196196
rb_imemo_tmpbuf_new_from_an_RString(VALUE str)
197197
{
198-
const void *src;
199198
VALUE imemo;
200-
rb_imemo_tmpbuf_t *tmpbuf;
201-
void *dst;
202199
size_t len;
203200

204201
StringValue(str);
205-
/* create tmpbuf to keep the pointer before xmalloc */
206-
imemo = rb_imemo_tmpbuf_new();
207-
tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
208202
len = RSTRING_LEN(str);
209-
src = RSTRING_PTR(str);
210-
dst = ruby_xmalloc(len);
211-
memcpy(dst, src, len);
212-
tmpbuf->ptr = dst;
203+
rb_alloc_tmp_buffer(&imemo, len);
204+
memcpy(RB_IMEMO_TMPBUF_PTR(imemo), RSTRING_PTR(str), len);
213205
return imemo;
214206
}
215207

0 commit comments

Comments
 (0)