summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-12 14:09:35 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-12 14:09:35 +0900
commitfcd6e4a7a444de7b6aaf2f0f38f3dbc043e8d495 (patch)
tree3bfadc6afdf0207edc5e5e1518fd841cdfca4991 /src/string.c
parent3308177c4d1a44120a1166f36624aff033e929e4 (diff)
parentd305a9dad701d2e21b3ca789820e6a78dc0e7b50 (diff)
downloadmruby-fcd6e4a7a444de7b6aaf2f0f38f3dbc043e8d495.tar.gz
mruby-fcd6e4a7a444de7b6aaf2f0f38f3dbc043e8d495.zip
Merge pull request #2049 from ksss/str-dup
mrb_str_dup return shared string instead of new string
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c
index 7ed83e590..51269644c 100644
--- a/src/string.c
+++ b/src/string.c
@@ -796,10 +796,11 @@ mrb_str_index(mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int offset)
mrb_value
mrb_str_dup(mrb_state *mrb, mrb_value str)
{
- /* should return shared string */
struct RString *s = mrb_str_ptr(str);
+ struct RString *dup = str_new(mrb, 0, 0);
- return mrb_str_new(mrb, STR_PTR(s), STR_LEN(s));
+ str_with_class(mrb, dup, str);
+ return str_replace(mrb, dup, s);
}
static mrb_value