summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-08-19 07:23:23 +0900
committerGitHub <[email protected]>2019-08-19 07:23:23 +0900
commitfeecb3321a8d528b29524f9ff7c991b5432f7600 (patch)
tree98d17eb59da674e4a1c177773832a93c9c52ccae /src/string.c
parent6f61b35bcf2e0686027c1f94c5b1ef5706ccea7d (diff)
parentaaa509dd076e7de654a6c555bec264083c145388 (diff)
downloadmruby-feecb3321a8d528b29524f9ff7c991b5432f7600.tar.gz
mruby-feecb3321a8d528b29524f9ff7c991b5432f7600.zip
Merge pull request #4640 from shuujii/also-use-str_init_shared-for-orig-in-str_make_shared
Also use `str_init_shared` for `orig` in `str_make_shared()`
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c
index ab53c2e69..10e20c3b1 100644
--- a/src/string.c
+++ b/src/string.c
@@ -77,7 +77,7 @@ str_init_shared(mrb_state *mrb, const struct RString *orig, struct RString *s, m
}
else {
shared = (mrb_shared_string *)mrb_malloc(mrb, sizeof(mrb_shared_string));
- shared->refcnt = 2;
+ shared->refcnt = 1;
shared->ptr = orig->as.heap.ptr;
shared->len = orig->as.heap.len;
}
@@ -516,7 +516,7 @@ mrb_memsearch(const void *x0, mrb_int m, const void *y0, mrb_int n)
static void
str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s)
{
- mrb_int len = RSTR_LEN(orig);
+ size_t len = (size_t)orig->as.heap.len;
mrb_assert(!RSTR_EMBED_P(orig));
if (RSTR_NOFREE_P(orig)) {
@@ -536,8 +536,7 @@ str_make_shared(mrb_state *mrb, struct RString *orig, struct RString *s)
orig->as.heap.ptr = (char *)mrb_realloc(mrb, orig->as.heap.ptr, len+1);
}
str_init_shared(mrb, orig, s, NULL);
- orig->as.heap.aux.shared = s->as.heap.aux.shared;
- RSTR_SET_TYPE_FLAG(orig, SHARED);
+ str_init_shared(mrb, orig, orig, s->as.heap.aux.shared);
}
}