summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-05-14 00:28:32 +0900
committerGitHub <[email protected]>2017-05-14 00:28:32 +0900
commit82bc036a5947a9b672568c664fd0a37071243c91 (patch)
tree185a5b9dd5b0ccf8833a71f12c45fa605bfc53a9
parent171e732dc7a73a046b2a56f2750cd81ea50bc5cb (diff)
parentbdb36b3404c3af9a202a3a2ed16155a799b7fc0c (diff)
downloadmruby-82bc036a5947a9b672568c664fd0a37071243c91.tar.gz
mruby-82bc036a5947a9b672568c664fd0a37071243c91.zip
Merge pull request #3657 from ksss/str-embed
Make string embad from shared
-rw-r--r--src/string.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c
index ba948b83b..e0b491bfb 100644
--- a/src/string.c
+++ b/src/string.c
@@ -685,13 +685,20 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
p = RSTR_PTR(s);
len = s->as.heap.len;
- ptr = (char *)mrb_malloc(mrb, (size_t)len + 1);
+ if (len < RSTRING_EMBED_LEN_MAX) {
+ RSTR_SET_EMBED_FLAG(s);
+ RSTR_SET_EMBED_LEN(s, len);
+ ptr = RSTR_PTR(s);
+ }
+ else {
+ ptr = (char *)mrb_malloc(mrb, (size_t)len + 1);
+ s->as.heap.ptr = ptr;
+ s->as.heap.aux.capa = len;
+ }
if (p) {
memcpy(ptr, p, len);
}
ptr[len] = '\0';
- s->as.heap.ptr = ptr;
- s->as.heap.aux.capa = len;
str_decref(mrb, shared);
}
RSTR_UNSET_SHARED_FLAG(s);