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:
parent
e2cabc22be
commit
2c31c3b45e
@ -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>
|
Wed Oct 07 20:17:29 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (newobj_of): divide fast path and slow path
|
* gc.c (newobj_of): divide fast path and slow path
|
||||||
|
5
benchmark/bm_vm2_string_literal.rb
Normal file
5
benchmark/bm_vm2_string_literal.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
i = 0
|
||||||
|
while i<6_000_000 # benchmark loop 2
|
||||||
|
i += 1
|
||||||
|
x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
end
|
23
string.c
23
string.c
@ -1250,28 +1250,37 @@ rb_str_dup(VALUE str)
|
|||||||
VALUE
|
VALUE
|
||||||
rb_str_resurrect(VALUE str)
|
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 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()) {
|
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
|
||||||
RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
|
RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
|
||||||
rb_sourcefile(), rb_sourceline());
|
rb_sourcefile(), rb_sourceline());
|
||||||
}
|
}
|
||||||
dup = str_alloc(rb_cString);
|
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 (flags & STR_NOEMBED) {
|
||||||
if (UNLIKELY(!(flags & FL_FREEZE))) {
|
if (UNLIKELY(!(flags & FL_FREEZE))) {
|
||||||
str = str_new_frozen(rb_cString, str);
|
str = str_new_frozen(rb_cString, str);
|
||||||
FL_SET_RAW(str, flags & FL_TAINT);
|
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);
|
RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
|
||||||
flags |= STR_SHARED;
|
flags |= STR_SHARED;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
|
||||||
|
char, embed_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
FL_SET_RAW(dup, flags & ~FL_FREEZE);
|
FL_SET_RAW(dup, flags & ~FL_FREEZE);
|
||||||
return dup;
|
return dup;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user