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

ruby-changes:60020

From: Nobuyoshi <ko1@a...>
Date: Wed, 12 Feb 2020 20:12:54 +0900 (JST)
Subject: [ruby-changes:60020] 160d3165eb (master): Copy non-inlined encoding index

https://git.ruby-lang.org/ruby.git/commit/?id=160d3165eb

From 160d3165eb095d81ae6e156f832a99728c853b01 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 12 Feb 2020 20:09:57 +0900
Subject: Copy non-inlined encoding index


diff --git a/string.c b/string.c
index 83c4780..3cfe3ad 100644
--- a/string.c
+++ b/string.c
@@ -1511,6 +1511,7 @@ str_duplicate(VALUE klass, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1511
 	;
     VALUE flags = FL_TEST_RAW(str, flag_mask);
     VALUE dup = str_alloc(klass);
+    int encidx = 0;
     MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
 	   char, embed_size);
     if (flags & STR_NOEMBED) {
@@ -1530,7 +1531,12 @@ str_duplicate(VALUE klass, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1531
 		   char, embed_size);
 	}
     }
+    if ((flags & ENCODING_MASK) == (ENCODING_INLINE_MAX<<ENCODING_SHIFT)) {
+	encidx = rb_enc_get_index(str);
+	flags &= ~ENCODING_MASK;
+    }
     FL_SET_RAW(dup, flags & ~FL_FREEZE);
+    if (encidx) rb_enc_associate_index(dup, encidx);
     return dup;
 }
 
diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb
index d571dd2..80bed39 100644
--- a/test/ruby/test_encoding.rb
+++ b/test/ruby/test_encoding.rb
@@ -74,6 +74,8 @@ class TestEncoding < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_encoding.rb#L74
       e = Encoding.list.last
       format = "%d".force_encoding(e)
       assert_equal("0", format % 0)
+      assert_equal(e, format.dup.encoding)
+      assert_equal(e, (format*1).encoding)
     end;
   end
 
-- 
cgit v0.10.2


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

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