summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-05 17:29:40 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-05 17:29:40 (GMT)
commit237332fceaf3e9f57d0be8295942d3347209ec75 (patch)
tree1c342bfb34217369462b41a88f119b842a2f45f2
parent355a0d8af1170db6249cd1269257cfcf2fd36050 (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--string.c21
2 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 759402f..71615b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/string.c b/string.c
index d80f43d..907b47c 100644
--- a/string.c
+++ b/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;
}
/*