Skip to content
Myr

Reduce allocation on string multiplication

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by William Langford · parent 9163e09 · Browse files · 1 file+9 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−11 removed

  • other:+9 added−11 removed

1 file+9 added−11 removed

modified:src/builtin.c+9 added-11 removed
318 unmodified lines
319 if (ak == JV_KIND_NUMBER) {320 str = b;321 num = a;322 }323 int n;324 size_t alen = jv_string_length_bytes(jv_copy(str));325 jv res = jv_copy(str);326327 for (n = jv_number_value(num) - 1; n > 0; n--)328 res = jv_string_append_buf(res, jv_string_value(str), alen);329323 jv res = jv_null();324 int n = jv_number_value(num);325 if (n > 0) {326 size_t alen = jv_string_length_bytes(jv_copy(str));327 res = jv_string_empty(alen * n);328 for (; n > 0; n--) {329 res = jv_string_append_buf(res, jv_string_value(str), alen);330 }331 }332 jv_free(str);333 jv_free(num);332 if (n < 0) {333 jv_free(res);334 return jv_null();335 }334 return res;335 } else if (ak == JV_KIND_OBJECT && bk == JV_KIND_OBJECT) {336 return jv_object_merge_recursive(a, b);337 } else {
1481 unmodified lines