diff --git a/contrib/20.r7rs/src/mutable-string.c b/contrib/20.r7rs/src/mutable-string.c index 85db9be0..01887976 100644 --- a/contrib/20.r7rs/src/mutable-string.c +++ b/contrib/20.r7rs/src/mutable-string.c @@ -4,13 +4,16 @@ void pic_str_set(pic_state *pic, pic_str *str, size_t i, char c) { pic_str *x, *y, *z, *tmp; + char buf[1]; if (pic_str_len(str) <= i) { pic_errorf(pic, "index out of range %d", i); } + buf[0] = c; + x = pic_str_sub(pic, str, 0, i); - y = pic_make_str_fill(pic, 1, c); + y = pic_make_str(pic, buf, 1); z = pic_str_sub(pic, str, i + 1, pic_str_len(str)); tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z)); diff --git a/extlib/benz/include/picrin/string.h b/extlib/benz/include/picrin/string.h index 2728e97b..b7448783 100644 --- a/extlib/benz/include/picrin/string.h +++ b/extlib/benz/include/picrin/string.h @@ -22,7 +22,6 @@ void pic_rope_decref(pic_state *, struct pic_rope *); pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t); pic_str *pic_make_str_cstr(pic_state *, const char *); -pic_str *pic_make_str_fill(pic_state *, size_t, char); char pic_str_ref(pic_state *, pic_str *, size_t); size_t pic_str_len(pic_str *); diff --git a/extlib/benz/string.c b/extlib/benz/string.c index 9d1060c3..cc4a0519 100644 --- a/extlib/benz/string.c +++ b/extlib/benz/string.c @@ -240,25 +240,6 @@ pic_make_str_cstr(pic_state *pic, const char *cstr) return pic_make_str(pic, cstr, strlen(cstr)); } -pic_str * -pic_make_str_fill(pic_state *pic, size_t len, char fill) -{ - size_t i; - char *buf = pic_malloc(pic, len); - pic_str *str; - - for (i = 0; i < len; ++i) { - buf[i] = fill; - } - buf[i] = '\0'; - - str = pic_make_str(pic, buf, len); - - pic_free(pic, buf); - - return str; -} - size_t pic_str_len(pic_str *str) { @@ -474,7 +455,16 @@ pic_str_make_string(pic_state *pic) pic_get_args(pic, "k|c", &len, &c); - return pic_obj_value(pic_make_str_fill(pic, len, c)); + { + size_t i; + char buf[len]; + + for (i = 0; i < len; ++i) { + buf[i] = c; + } + + return pic_obj_value(pic_make_str(pic, buf, len)); + } } static pic_value