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

ruby-changes:64222

From: Koichi <ko1@a...>
Date: Thu, 17 Dec 2020 03:44:36 +0900 (JST)
Subject: [ruby-changes:64222] 2a3324fcd2 (master): No sync on ASCII/US_ASCCII/UTF-8

https://git.ruby-lang.org/ruby.git/commit/?id=2a3324fcd2

From 2a3324fcd2f9681e167b2619563a5c26e1a362fe Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 17 Dec 2020 01:56:30 +0900
Subject: No sync on ASCII/US_ASCCII/UTF-8

rb_enc_from_index(index) doesn't need locking if index specify
ASCII/US_ASCCII/UTF-8.
rb_enc_from_index() is called frequently so it has impact.

                               user     system      total        real
r_parallel/miniruby       174  0.000209   0.000000   5.559872 (  1.811501)
r_parallel/master_mini    175  0.000238   0.000000  12.664707 (  3.523641)

(repeat x1000 `s.split(/,/)` where s = '0,,' * 1000)

diff --git a/encoding.c b/encoding.c
index 64748ce..330be29 100644
--- a/encoding.c
+++ b/encoding.c
@@ -418,9 +418,16 @@ rb_encoding * https://github.com/ruby/ruby/blob/trunk/encoding.c#L418
 rb_enc_from_index(int index)
 {
     rb_encoding *enc;
-    GLOBAL_ENC_TABLE_EVAL(enc_table,
-                          enc = enc_from_index(enc_table, index));
-    return enc;
+
+    switch (index) {
+      case ENCINDEX_ASCII:    return global_enc_ascii;
+      case ENCINDEX_UTF_8:    return global_enc_utf_8;
+      case ENCINDEX_US_ASCII: return global_enc_us_ascii;
+      default:
+        GLOBAL_ENC_TABLE_EVAL(enc_table,
+                              enc = enc_from_index(enc_table, index));
+        return enc;
+    }
 }
 
 int
-- 
cgit v0.10.2


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

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