diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-12 14:20:18 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-18 22:17:48 +0900 |
| commit | f1767fd079a74ca5c5ec77f101816b7d657509d8 (patch) | |
| tree | f74df66a1fd0ac737ece521a39746dc5a16b2843 /src/string.c | |
| parent | 722d123b870af2a36a7ba3c0b5228b340269044b (diff) | |
| download | mruby-f1767fd079a74ca5c5ec77f101816b7d657509d8.tar.gz mruby-f1767fd079a74ca5c5ec77f101816b7d657509d8.zip | |
Separate `mrb_str_buf_new` and `mrb_str_new_capa`.
`mrb_str_buf_new` is an old function that ensures capacity size of
`MRB_STR_BUF_MIN_SIZE` minimum. Usually one need to use
`mrb_str_new_capa` instead.
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/string.c b/src/string.c index 551d33a12..801e77f16 100644 --- a/src/string.c +++ b/src/string.c @@ -94,12 +94,8 @@ mrb_str_new_empty(mrb_state *mrb, mrb_value str) return mrb_obj_value(s); } -#ifndef MRB_STR_BUF_MIN_SIZE -# define MRB_STR_BUF_MIN_SIZE 128 -#endif - MRB_API mrb_value -mrb_str_buf_new(mrb_state *mrb, size_t capa) +mrb_str_new_capa(mrb_state *mrb, size_t capa) { struct RString *s; @@ -108,9 +104,6 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa) if (capa >= MRB_INT_MAX) { mrb_raise(mrb, E_ARGUMENT_ERROR, "string capacity size too big"); } - if (capa < MRB_STR_BUF_MIN_SIZE) { - capa = MRB_STR_BUF_MIN_SIZE; - } s->as.heap.len = 0; s->as.heap.aux.capa = (mrb_int)capa; s->as.heap.ptr = (char *)mrb_malloc(mrb, capa+1); @@ -119,6 +112,19 @@ mrb_str_buf_new(mrb_state *mrb, size_t capa) return mrb_obj_value(s); } +#ifndef MRB_STR_BUF_MIN_SIZE +# define MRB_STR_BUF_MIN_SIZE 128 +#endif + +MRB_API mrb_value +mrb_str_buf_new(mrb_state *mrb, size_t capa) +{ + if (capa < MRB_STR_BUF_MIN_SIZE) { + capa = MRB_STR_BUF_MIN_SIZE; + } + return mrb_str_new_capa(mrb, capa); +} + static void resize_capa(mrb_state *mrb, struct RString *s, size_t capacity) { |
