Commit c9f3fd47 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #986 from monaka/pr-use-mrb_obj_alloc_string-instead-of-str_alloc

Remove str_alloc(). Use mrb_obj_alloc_string() instead.
parents 3f4c2d45 588f5150
...@@ -106,21 +106,6 @@ str_mod_check(mrb_state *mrb, mrb_value str, char *p, mrb_int len) ...@@ -106,21 +106,6 @@ str_mod_check(mrb_state *mrb, mrb_value str, char *p, mrb_int len)
#define mrb_obj_alloc_string(mrb) ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class)) #define mrb_obj_alloc_string(mrb) ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class))
static struct RString*
str_alloc(mrb_state *mrb, struct RClass *c)
{
struct RString* s;
s = mrb_obj_alloc_string(mrb);
s->c = c;
s->ptr = 0;
s->len = 0;
s->aux.capa = 0;
return s;
}
/* char offset to byte offset */ /* char offset to byte offset */
int int
mrb_str_offset(mrb_state *mrb, mrb_value str, int pos) mrb_str_offset(mrb_state *mrb, mrb_value str, int pos)
...@@ -131,8 +116,9 @@ mrb_str_offset(mrb_state *mrb, mrb_value str, int pos) ...@@ -131,8 +116,9 @@ mrb_str_offset(mrb_state *mrb, mrb_value str, int pos)
static struct RString* static struct RString*
str_new(mrb_state *mrb, const char *p, int len) str_new(mrb_state *mrb, const char *p, int len)
{ {
struct RString *s = str_alloc(mrb, mrb->string_class); struct RString *s;
s = mrb_obj_alloc_string(mrb);
s->len = len; s->len = len;
s->aux.capa = len; s->aux.capa = len;
s->ptr = (char *)mrb_malloc(mrb, len+1); s->ptr = (char *)mrb_malloc(mrb, len+1);
...@@ -315,7 +301,7 @@ mrb_str_literal(mrb_state *mrb, mrb_value str) ...@@ -315,7 +301,7 @@ mrb_str_literal(mrb_state *mrb, mrb_value str)
struct RString *s, *orig; struct RString *s, *orig;
mrb_shared_string *shared; mrb_shared_string *shared;
s = str_alloc(mrb, mrb->string_class); s = mrb_obj_alloc_string(mrb);
orig = mrb_str_ptr(str); orig = mrb_str_ptr(str);
if (!(orig->flags & MRB_STR_SHARED)) { if (!(orig->flags & MRB_STR_SHARED)) {
str_make_shared(mrb, mrb_str_ptr(str)); str_make_shared(mrb, mrb_str_ptr(str));
...@@ -324,6 +310,7 @@ mrb_str_literal(mrb_state *mrb, mrb_value str) ...@@ -324,6 +310,7 @@ mrb_str_literal(mrb_state *mrb, mrb_value str)
shared->refcnt++; shared->refcnt++;
s->ptr = shared->ptr; s->ptr = shared->ptr;
s->len = shared->len; s->len = shared->len;
s->aux.capa = 0;
s->aux.shared = shared; s->aux.shared = shared;
s->flags |= MRB_STR_SHARED; s->flags |= MRB_STR_SHARED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment