1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-29 03:19:54 +00:00

No temporary buffer in PR #87

This commit is contained in:
Calvin Rose 2019-05-08 10:53:23 -04:00
parent 1759252071
commit bfb0cb331e

View File

@ -208,15 +208,9 @@ static Janet cfun_buffer_chars(int32_t argc, Janet *argv) {
JanetBuffer *buffer = janet_getbuffer(argv, 0);
for (i = 1; i < argc; i++) {
JanetByteView view = janet_getbytes(argv, i);
if (janet_checktype(argv[i], JANET_BUFFER)) {
JanetBuffer *other = janet_getbuffer(argv, i);
if (buffer == other) {
JanetBuffer *tmp = janet_buffer(buffer->count);
janet_buffer_setcount(tmp, buffer->count);
memcpy(tmp->data, buffer->data, buffer->count);
view.bytes = tmp->data;
view.len = tmp->count;
}
if (view.bytes == buffer->data) {
janet_buffer_ensure(buffer, buffer->count + view.len, 2);
view.bytes = buffer->data;
}
janet_buffer_push_bytes(buffer, view.bytes, view.len);
}