1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-10-07 11:43:17 +00:00
parent e2cabc22be
commit 2c31c3b45e
3 changed files with 28 additions and 9 deletions

View file

@ -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

View file

@ -0,0 +1,5 @@
i = 0
while i<6_000_000 # benchmark loop 2
i += 1
x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
end

View file

@ -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;