summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 11:43:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 11:43:17 +0000
commit2c31c3b45ed5ef3c2c0a2308957fb98334367cf4 (patch)
tree650931b359039b52c0e9f010957bf6ce21bea796
parente2cabc22be830ac2a1871dc6c8107cbd759da7ab (diff)
string.c: fix non-embedded string
* string.c (rb_str_resurrect): fix resurrection of short enough to be embedded but not embedded string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--benchmark/bm_vm2_string_literal.rb5
-rw-r--r--string.c27
3 files changed, 28 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 0d66bde785..8da24e4fdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Oct 7 20:43:14 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_resurrect): fix resurrection of short enough to
+ be embedded but not embedded string.
+
Wed Oct 07 20:17:29 2015 Koichi Sasada <ko1@atdot.net>
* gc.c (newobj_of): divide fast path and slow path
diff --git a/benchmark/bm_vm2_string_literal.rb b/benchmark/bm_vm2_string_literal.rb
new file mode 100644
index 0000000000..1d73036849
--- /dev/null
+++ b/benchmark/bm_vm2_string_literal.rb
@@ -0,0 +1,5 @@
+i = 0
+while i<6_000_000 # benchmark loop 2
+ i += 1
+ x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+end
diff --git a/string.c b/string.c
index a164c34492..c2668d1375 100644
--- a/string.c
+++ b/string.c
@@ -1250,27 +1250,36 @@ rb_str_dup(VALUE str)
VALUE
rb_str_resurrect(VALUE str)
{
+ enum {embed_size = RSTRING_EMBED_LEN_MAX + 1};
+ const VALUE flag_mask =
+ RSTRING_NOEMBED | RSTRING_EMBED_LEN_MASK |
+ ENC_CODERANGE_MASK | ENCODING_MASK |
+ FL_TAINT | FL_FREEZE
+ ;
+ VALUE flags = FL_TEST_RAW(str, flag_mask);
VALUE dup;
- VALUE flags = FL_TEST_RAW(str,
- RSTRING_NOEMBED |
- RSTRING_EMBED_LEN_MASK |
- ENC_CODERANGE_MASK |
- ENCODING_MASK |
- FL_TAINT | FL_FREEZE);
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
rb_sourcefile(), rb_sourceline());
}
dup = str_alloc(rb_cString);
- MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary, VALUE, 3);
+ MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
+ char, embed_size);
if (flags & STR_NOEMBED) {
if (UNLIKELY(!(flags & FL_FREEZE))) {
str = str_new_frozen(rb_cString, str);
FL_SET_RAW(str, flags & FL_TAINT);
+ flags = FL_TEST_RAW(str, flag_mask);
+ }
+ if (flags & STR_NOEMBED) {
+ RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
+ flags |= STR_SHARED;
+ }
+ else {
+ MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
+ char, embed_size);
}
- RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
- flags |= STR_SHARED;
}
FL_SET_RAW(dup, flags & ~FL_FREEZE);
return dup;