diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-04 14:04:54 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-04 14:04:54 +0000 |
commit | e5684558262ead5253b9fce36efaea6a6ae6acab (patch) | |
tree | d1de4248f3d225352bafeb8b57ab9d7f3bff42b8 | |
parent | 805d6f6f3c95a4407990cbd663f26cfb5171739e (diff) | |
download | ruby-e5684558262ead5253b9fce36efaea6a6ae6acab.tar.gz |
string.c: grapheme clusters on frozen string
* string.c (rb_str_enumerate_grapheme_clusters): enumerate on
shared frozen string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | string.c | 5 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 2 |
2 files changed, 6 insertions, 1 deletions
@@ -8019,6 +8019,7 @@ rb_str_codepoints(VALUE str) static VALUE rb_str_enumerate_grapheme_clusters(VALUE str, VALUE ary) { + VALUE orig = str; regex_t *reg_grapheme_cluster = NULL; static regex_t *reg_grapheme_cluster_utf8 = NULL; int encidx = ENCODING_GET(str); @@ -8046,6 +8047,7 @@ rb_str_enumerate_grapheme_clusters(VALUE str, VALUE ary) } } + if (!ary) str = rb_str_new_frozen(str); ptr = RSTRING_PTR(str); end = RSTRING_END(str); @@ -8060,10 +8062,11 @@ rb_str_enumerate_grapheme_clusters(VALUE str, VALUE ary) ENUM_ELEM(ary, rb_enc_str_new(ptr, len, enc)); ptr += len; } + RB_GC_GUARD(str); if (ary) return ary; else - return str; + return orig; } /* diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index f662a83c12..c7f4521e27 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -919,6 +919,8 @@ CODE assert_equal ["\u000A", "\u0308"], "\u{a 308}".each_grapheme_cluster.to_a assert_equal ["\u000D", "\u0308"], "\u{d 308}".each_grapheme_cluster.to_a assert_equal ["a", "b", "c"], "abc".b.each_grapheme_cluster.to_a + s = ("x"+"\u{10ABCD}"*250000) + assert_empty(s.each_grapheme_cluster {s.clear}) end def test_grapheme_clusters |