summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/string.c b/string.c
index cf7f484c7d..6a6859b1f2 100644
--- a/string.c
+++ b/string.c
@@ -1285,8 +1285,9 @@ rb_str_subseq(VALUE str, long beg, long len)
{
VALUE str2;
- if (RSTRING_LEN(str) == beg + len) {
- str2 = rb_str_new_shared(str);
+ if (RSTRING_LEN(str) == beg + len &&
+ RSTRING_EMBED_LEN_MAX < len) {
+ str2 = rb_str_new_shared(rb_str_new_frozen(str));
rb_str_drop_bytes(str2, beg);
}
else {