rename API mrb_str_dup_static() -> mrb_str_pool()

parent 217595c3
...@@ -50,7 +50,6 @@ char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); ...@@ -50,7 +50,6 @@ char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr); char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr);
int mrb_str_offset(mrb_state *mrb, mrb_value str, int pos); int mrb_str_offset(mrb_state *mrb, mrb_value str, int pos);
mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_dup_static(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
mrb_value mrb_str_cat_cstr(mrb_state *, mrb_value, const char *); mrb_value mrb_str_cat_cstr(mrb_state *, mrb_value, const char *);
mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck); mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck);
...@@ -66,6 +65,7 @@ mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2); ...@@ -66,6 +65,7 @@ mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2); int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str); char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str);
/* For backward compatibility */ /* For backward compatibility */
static inline mrb_value static inline mrb_value
......
...@@ -440,7 +440,7 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -440,7 +440,7 @@ new_lit(codegen_scope *s, mrb_value val)
switch (mrb_type(val)) { switch (mrb_type(val)) {
case MRB_TT_STRING: case MRB_TT_STRING:
*pv = mrb_str_dup_static(s->mrb, val); *pv = mrb_str_pool(s->mrb, val);
break; break;
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
......
...@@ -110,7 +110,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len) ...@@ -110,7 +110,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, uint32_t *len)
break; break;
case IREP_TT_STRING: case IREP_TT_STRING:
irep->pool[i] = mrb_str_dup_static(mrb, s); irep->pool[i] = mrb_str_pool(mrb, s);
break; break;
default: default:
......
...@@ -147,6 +147,28 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep) ...@@ -147,6 +147,28 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
mrb_free(mrb, irep); mrb_free(mrb, irep);
} }
mrb_value
mrb_str_pool(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
struct RString *ns;
mrb_int len;
ns = (struct RString *)mrb_malloc(mrb, sizeof(struct RString));
ns->tt = MRB_TT_STRING;
ns->c = mrb->string_class;
len = s->len;
ns->len = len;
ns->ptr = (char *)mrb_malloc(mrb, (size_t)len+1);
if (s->ptr) {
memcpy(ns->ptr, s->ptr, len);
}
ns->ptr[len] = '\0';
return mrb_obj_value(ns);
}
void void
mrb_free_context(mrb_state *mrb, struct mrb_context *c) mrb_free_context(mrb_state *mrb, struct mrb_context *c)
{ {
......
...@@ -734,28 +734,6 @@ mrb_str_dup(mrb_state *mrb, mrb_value str) ...@@ -734,28 +734,6 @@ mrb_str_dup(mrb_state *mrb, mrb_value str)
return mrb_str_new(mrb, s->ptr, s->len); return mrb_str_new(mrb, s->ptr, s->len);
} }
mrb_value
mrb_str_dup_static(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
struct RString *ns;
mrb_int len;
ns = (struct RString *)mrb_malloc(mrb, sizeof(struct RString));
ns->tt = MRB_TT_STRING;
ns->c = mrb->string_class;
len = s->len;
ns->len = len;
ns->ptr = (char *)mrb_malloc(mrb, (size_t)len+1);
if (s->ptr) {
memcpy(ns->ptr, s->ptr, len);
}
ns->ptr[len] = '\0';
return mrb_obj_value(ns);
}
static mrb_value static mrb_value
mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx) mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
{ {
......
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