[前][次][番号順一覧][スレッド一覧]

ruby-changes:39967

From: nobu <ko1@a...>
Date: Tue, 6 Oct 2015 02:29:47 +0900 (JST)
Subject: [ruby-changes:39967] nobu:r52048 (trunk): string.c: optimize rb_str_resurrect

nobu	2015-10-06 02:29:40 +0900 (Tue, 06 Oct 2015)

  New Revision: 52048

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52048

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52047)
+++ ChangeLog	(revision 52048)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct  6 02:29:38 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* test/ruby/test_thread.rb (test_handle_interrupt_blocking): check if
Index: string.c
===================================================================
--- string.c	(revision 52047)
+++ string.c	(revision 52048)
@@ -1250,11 +1250,30 @@ rb_str_dup(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1250
 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;
 }
 
 /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]