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

ruby-changes:39992

From: nobu <ko1@a...>
Date: Wed, 7 Oct 2015 20:43:39 +0900 (JST)
Subject: [ruby-changes:39992] nobu:r52073 (trunk): string.c: fix non-embedded string

nobu	2015-10-07 20:43:17 +0900 (Wed, 07 Oct 2015)

  New Revision: 52073

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

  Log:
    string.c: fix non-embedded string
    
    * string.c (rb_str_resurrect): fix resurrection of short enough to
      be embedded but not embedded string.

  Added files:
    trunk/benchmark/bm_vm2_string_literal.rb
  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52072)
+++ ChangeLog	(revision 52073)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct  7 20:43:14 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@a...>
 
 	* gc.c (newobj_of): divide fast path and slow path
Index: string.c
===================================================================
--- string.c	(revision 52072)
+++ string.c	(revision 52073)
@@ -1250,27 +1250,36 @@ rb_str_dup(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1250
 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;
Index: benchmark/bm_vm2_string_literal.rb
===================================================================
--- benchmark/bm_vm2_string_literal.rb	(revision 0)
+++ benchmark/bm_vm2_string_literal.rb	(revision 52073)
@@ -0,0 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/bm_vm2_string_literal.rb#L1
+i = 0
+while i<6_000_000 # benchmark loop 2
+  i += 1
+  x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+end

Property changes on: benchmark/bm_vm2_string_literal.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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