mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: optimize rb_str_resurrect
* string.c (rb_str_resurrect): optimize by short circuit to copy hidden string without checking length, encoding and so on. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
355a0d8af1
commit
237332fcea
2 changed files with 25 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Oct 6 02:29:38 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_resurrect): optimize by short circuit to copy
|
||||
hidden string without checking length, encoding and so on.
|
||||
|
||||
Mon Oct 5 23:08:17 2015 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_thread.rb (test_handle_interrupt_blocking): check if
|
||||
|
|
21
string.c
21
string.c
|
@ -1250,11 +1250,30 @@ rb_str_dup(VALUE str)
|
|||
VALUE
|
||||
rb_str_resurrect(VALUE str)
|
||||
{
|
||||
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());
|
||||
}
|
||||
return str_duplicate(rb_cString, str);
|
||||
dup = str_alloc(rb_cString);
|
||||
MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary, VALUE, 3);
|
||||
if (flags & STR_NOEMBED) {
|
||||
if (UNLIKELY(!(flags & FL_FREEZE))) {
|
||||
str = str_new_frozen(rb_cString, str);
|
||||
FL_SET_RAW(str, flags & FL_TAINT);
|
||||
}
|
||||
RB_OBJ_WRITE(dup, &RSTRING(dup)->as.heap.aux.shared, str);
|
||||
flags |= STR_SHARED;
|
||||
}
|
||||
FL_SET_RAW(dup, flags & ~FL_FREEZE);
|
||||
return dup;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue