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

ruby-changes:63921

From: Yusuke <ko1@a...>
Date: Sat, 5 Dec 2020 03:09:10 +0900 (JST)
Subject: [ruby-changes:63921] 6a51d393ca (master): [ruby/reline] Improve the regexps for EastAsianWidth

https://git.ruby-lang.org/ruby.git/commit/?id=6a51d393ca

From 6a51d393ca834984737a2fa60e9a37bc9dec2a03 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 19 Oct 2020 23:22:47 +0900
Subject: [ruby/reline] Improve the regexps for EastAsianWidth

A character class is about three times faster than Regexp alternatives

https://github.com/ruby/reline/commit/57c7955c55

diff --git a/lib/reline/unicode/east_asian_width.rb b/lib/reline/unicode/east_asian_width.rb
index 7e66f36..b6e4f57 100644
--- a/lib/reline/unicode/east_asian_width.rb
+++ b/lib/reline/unicode/east_asian_width.rb
@@ -3,1162 +3,1162 @@ class Reline::Unicode::EastAsianWidth https://github.com/ruby/ruby/blob/trunk/lib/reline/unicode/east_asian_width.rb#L3
   # http://www.unicode.org/Public/13.0.0/ucd/EastAsianWidth.txt
 
   # Fullwidth
-  TYPE_F = /^(
-    \u{3000} |
-    [\u{FF01}-\u{FF60}] |
-    [\u{FFE0}-\u{FFE6}]
-  )/x
+  TYPE_F = /^([#{ %W(
+    \u{3000}
+    \u{FF01}-\u{FF60}
+    \u{FFE0}-\u{FFE6}
+  ).join }])/x
 
   # Halfwidth
-  TYPE_H = /^(
-    \u{20A9} |
-    [\u{FF61}-\u{FFBE}] |
-    [\u{FFC2}-\u{FFC7}] |
-    [\u{FFCA}-\u{FFCF}] |
-    [\u{FFD2}-\u{FFD7}] |
-    [\u{FFDA}-\u{FFDC}] |
-    [\u{FFE8}-\u{FFEE}]
-  )/x
+  TYPE_H = /^([#{ %W(
+    \u{20A9}
+    \u{FF61}-\u{FFBE}
+    \u{FFC2}-\u{FFC7}
+    \u{FFCA}-\u{FFCF}
+    \u{FFD2}-\u{FFD7}
+    \u{FFDA}-\u{FFDC}
+    \u{FFE8}-\u{FFEE}
+  ).join }])/x
 
   # Wide
-  TYPE_W = /^(
-    [\u{1100}-\u{115F}] |
-    [\u{231A}-\u{231B}] |
-    [\u{2329}-\u{232A}] |
-    [\u{23E9}-\u{23EC}] |
-    \u{23F0} |
-    \u{23F3} |
-    [\u{25FD}-\u{25FE}] |
-    [\u{2614}-\u{2615}] |
-    [\u{2648}-\u{2653}] |
-    \u{267F} |
-    \u{2693} |
-    \u{26A1} |
-    [\u{26AA}-\u{26AB}] |
-    [\u{26BD}-\u{26BE}] |
-    [\u{26C4}-\u{26C5}] |
-    \u{26CE} |
-    \u{26D4} |
-    \u{26EA} |
-    [\u{26F2}-\u{26F3}] |
-    \u{26F5} |
-    \u{26FA} |
-    \u{26FD} |
-    \u{2705} |
-    [\u{270A}-\u{270B}] |
-    \u{2728} |
-    \u{274C} |
-    \u{274E} |
-    [\u{2753}-\u{2755}] |
-    \u{2757} |
-    [\u{2795}-\u{2797}] |
-    \u{27B0} |
-    \u{27BF} |
-    [\u{2B1B}-\u{2B1C}] |
-    \u{2B50} |
-    \u{2B55} |
-    [\u{2E80}-\u{2E99}] |
-    [\u{2E9B}-\u{2EF3}] |
-    [\u{2F00}-\u{2FD5}] |
-    [\u{2FF0}-\u{2FFB}] |
-    [\u{3001}-\u{303E}] |
-    [\u{3041}-\u{3096}] |
-    [\u{3099}-\u{30FF}] |
-    [\u{3105}-\u{312F}] |
-    [\u{3131}-\u{318E}] |
-    [\u{3190}-\u{31E3}] |
-    [\u{31F0}-\u{321E}] |
-    [\u{3220}-\u{3247}] |
-    [\u{3250}-\u{4DBF}] |
-    [\u{4E00}-\u{A48C}] |
-    [\u{A490}-\u{A4C6}] |
-    [\u{A960}-\u{A97C}] |
-    [\u{AC00}-\u{D7A3}] |
-    [\u{F900}-\u{FAFF}] |
-    [\u{FE10}-\u{FE19}] |
-    [\u{FE30}-\u{FE52}] |
-    [\u{FE54}-\u{FE66}] |
-    [\u{FE68}-\u{FE6B}] |
-    [\u{16FE0}-\u{16FE4}] |
-    [\u{16FF0}-\u{16FF1}] |
-    [\u{17000}-\u{187F7}] |
-    [\u{18800}-\u{18CD5}] |
-    [\u{18D00}-\u{18D08}] |
-    [\u{1B000}-\u{1B11E}] |
-    [\u{1B150}-\u{1B152}] |
-    [\u{1B164}-\u{1B167}] |
-    [\u{1B170}-\u{1B2FB}] |
-    \u{1F004} |
-    \u{1F0CF} |
-    \u{1F18E} |
-    [\u{1F191}-\u{1F19A}] |
-    [\u{1F200}-\u{1F202}] |
-    [\u{1F210}-\u{1F23B}] |
-    [\u{1F240}-\u{1F248}] |
-    [\u{1F250}-\u{1F251}] |
-    [\u{1F260}-\u{1F265}] |
-    [\u{1F300}-\u{1F320}] |
-    [\u{1F32D}-\u{1F335}] |
-    [\u{1F337}-\u{1F37C}] |
-    [\u{1F37E}-\u{1F393}] |
-    [\u{1F3A0}-\u{1F3CA}] |
-    [\u{1F3CF}-\u{1F3D3}] |
-    [\u{1F3E0}-\u{1F3F0}] |
-    \u{1F3F4} |
-    [\u{1F3F8}-\u{1F43E}] |
-    \u{1F440} |
-    [\u{1F442}-\u{1F4FC}] |
-    [\u{1F4FF}-\u{1F53D}] |
-    [\u{1F54B}-\u{1F54E}] |
-    [\u{1F550}-\u{1F567}] |
-    \u{1F57A} |
-    [\u{1F595}-\u{1F596}] |
-    \u{1F5A4} |
-    [\u{1F5FB}-\u{1F64F}] |
-    [\u{1F680}-\u{1F6C5}] |
-    \u{1F6CC} |
-    [\u{1F6D0}-\u{1F6D2}] |
-    [\u{1F6D5}-\u{1F6D7}] |
-    [\u{1F6EB}-\u{1F6EC}] |
-    [\u{1F6F4}-\u{1F6FC}] |
-    [\u{1F7E0}-\u{1F7EB}] |
-    [\u{1F90C}-\u{1F93A}] |
-    [\u{1F93C}-\u{1F945}] |
-    [\u{1F947}-\u{1F978}] |
-    [\u{1F97A}-\u{1F9CB}] |
-    [\u{1F9CD}-\u{1F9FF}] |
-    [\u{1FA70}-\u{1FA74}] |
-    [\u{1FA78}-\u{1FA7A}] |
-    [\u{1FA80}-\u{1FA86}] |
-    [\u{1FA90}-\u{1FAA8}] |
-    [\u{1FAB0}-\u{1FAB6}] |
-    [\u{1FAC0}-\u{1FAC2}] |
-    [\u{1FAD0}-\u{1FAD6}] |
-    [\u{20000}-\u{2FFFD}] |
-    [\u{30000}-\u{3FFFD}]
-  )/x
+  TYPE_W = /^([#{ %W(
+    \u{1100}-\u{115F}
+    \u{231A}-\u{231B}
+    \u{2329}-\u{232A}
+    \u{23E9}-\u{23EC}
+    \u{23F0}
+    \u{23F3}
+    \u{25FD}-\u{25FE}
+    \u{2614}-\u{2615}
+    \u{2648}-\u{2653}
+    \u{267F}
+    \u{2693}
+    \u{26A1}
+    \u{26AA}-\u{26AB}
+    \u{26BD}-\u{26BE}
+    \u{26C4}-\u{26C5}
+    \u{26CE}
+    \u{26D4}
+    \u{26EA}
+    \u{26F2}-\u{26F3}
+    \u{26F5}
+    \u{26FA}
+    \u{26FD}
+    \u{2705}
+    \u{270A}-\u{270B}
+    \u{2728}
+    \u{274C}
+    \u{274E}
+    \u{2753}-\u{2755}
+    \u{2757}
+    \u{2795}-\u{2797}
+    \u{27B0}
+    \u{27BF}
+    \u{2B1B}-\u{2B1C}
+    \u{2B50}
+    \u{2B55}
+    \u{2E80}-\u{2E99}
+    \u{2E9B}-\u{2EF3}
+    \u{2F00}-\u{2FD5}
+    \u{2FF0}-\u{2FFB}
+    \u{3001}-\u{303E}
+    \u{3041}-\u{3096}
+    \u{3099}-\u{30FF}
+    \u{3105}-\u{312F}
+    \u{3131}-\u{318E}
+    \u{3190}-\u{31E3}
+    \u{31F0}-\u{321E}
+    \u{3220}-\u{3247}
+    \u{3250}-\u{4DBF}
+    \u{4E00}-\u{A48C}
+    \u{A490}-\u{A4C6}
+    \u{A960}-\u{A97C}
+    \u{AC00}-\u{D7A3}
+    \u{F900}-\u{FAFF}
+    \u{FE10}-\u{FE19}
+    \u{FE30}-\u{FE52}
+    \u{FE54}-\u{FE66}
+    \u{FE68}-\u{FE6B}
+    \u{16FE0}-\u{16FE4}
+    \u{16FF0}-\u{16FF1}
+    \u{17000}-\u{187F7}
+    \u{18800}-\u{18CD5}
+    \u{18D00}-\u{18D08}
+    \u{1B000}-\u{1B11E}
+    \u{1B150}-\u{1B152}
+    \u{1B164}-\u{1B167}
+    \u{1B170}-\u{1B2FB}
+    \u{1F004}
+    \u{1F0CF}
+    \u{1F18E}
+    \u{1F191}-\u{1F19A}
+    \u{1F200}-\u{1F202}
+    \u{1F210}-\u{1F23B}
+    \u{1F240}-\u{1F248}
+    \u{1F250}-\u{1F251}
+    \u{1F260}-\u{1F265}
+    \u{1F300}-\u{1F320}
+    \u{1F32D}-\u{1F335}
+    \u{1F337}-\u{1F37C}
+    \u{1F37E}-\u{1F393}
+    \u{1F3A0}-\u{1F3CA}
+    \u{1F3CF}-\u{1F3D3}
+    \u{1F3E0}-\u{1F3F0}
+    \u{1F3F4}
+    \u{1F3F8}-\u{1F43E}
+    \u{1F440}
+    \u{1F442}-\u{1F4FC}
+    \u{1F4FF}-\u{1F53D}
+    \u{1F54B}-\u{1F54E}
+    \u{1F550}-\u{1F567}
+    \u{1F57A}
+    \u{1F595}-\u{1F596}
+    \u{1F5A4}
+    \u{1F5FB}-\u{1F64F}
+    \u{1F680}-\u{1F6C5}
+    \u{1F6CC}
+    \u{1F6D0}-\u{1F6D2}
+    \u{1F6D5}-\u{1F6D7}
+    \u{1F6EB}-\u{1F6EC}
+    \u{1F6F4}-\u{1F6FC}
+    \u{1F7E0}-\u{1F7EB}
+    \u{1F90C}-\u{1F93A}
+    \u{1F93C}-\u{1F945}
+    \u{1F947}-\u{1F978}
+    \u{1F97A}-\u{1F9CB}
+    \u{1F9CD}-\u{1F9FF}
+    \u{1FA70}-\u{1FA74}
+    \u{1FA78}-\u{1FA7A}
+    \u{1FA80}-\u{1FA86}
+    \u{1FA90}-\u{1FAA8}
+    \u{1FAB0}-\u{1FAB6}
+    \u{1FAC0}-\u{1FAC2}
+    \u{1FAD0}-\u{1FAD6}
+    \u{20000}-\u{2FFFD}
+    \u{30000}-\u{3FFFD}
+  ).join }])/x
 
   # Narrow
-  TYPE_NA = /^(
-    [\u{0020}-\u{007E}] |
-    [\u{00A2}-\u{00A3}] |
-    [\u{00A5}-\u{00A6}] |
-    \u{00AC} |
-    \u{00AF} |
-    [\u{27E6}-\u{27ED}] |
-    [\u{2985}-\u{2986}]
-  )/x
+  TYPE_NA = /^([#{ %W(
+    \u{0020}-\u{007E}
+    \u{00A2}-\u{00A3}
+    \u{00A5}-\u{00A6}
+    \u{00AC}
+    \u{00AF}
+    \u{27E6}-\u{27ED}
+    \u{2985}-\u{2986}
+  ).join }])/x
 
   # Ambiguous
-  TYPE_A = /^(
-    \u{00A1} |
-    \u{00A4} |
-    [\u{00A7}-\u{00A8}] |
-    \u{00AA} |
-    [\u{00AD}-\u{00AE}] |
-    [\u{00B0}-\u{00B4}] |
-    [\u{00B6}-\u{00BA}] |
-    [\u{00BC}-\u{00BF}] |
-    \u{00C6} |
-    \u{00D0} |
-    [\u{00D7}-\u{00D8}] |
-    [\u{00DE}-\u{00E1}] |
-    \u{00E6} |
-    [\u{00E8}-\u{00EA}] |
-    [\u{00EC}-\u{00ED}] |
-    \u{00F0} |
-    [\u{00F2}-\u{00F3}] |
-    [\u{00F7}-\u{00FA}] |
-    \u{00FC} |
-    \u{00FE} |
-    \u{0101} |
-    \u{0111} |
-    \u{0113} |
-    \u{011B} |
-    [\u{0126}-\u{0127}] |
-    \u{012B} |
-    [\u{0131}-\u{0133}] |
-    \u{0138} |
-    [\u{013F}-\u{0142}] |
-    \u{0144} |
-    [\u{0148}-\u{014B}] |
-    \u{014D} |
-    [\u{0152}-\u{0153}] |
-    [\u{0166}-\u{0167}] |
-    \u{016B} |
-    \u{01CE} |
-    \u{01D0} |
-    \u{01D2} |
-    \u{01D4} |
-    \u{01D6} |
-    \u{01D8} |
-    \u{01DA} |
-    \u{01DC} |
-    \u{0251} |
-    \u{0261} |
-    \u{02C4} |
-    \u{02C7} |
-    [\u{02C9}-\u{02CB}] |
-    \u{02CD} |
-    \u{02D0} |
-    [\u{02D8}-\u{02DB}] |
-    \u{02DD} |
-    \u{02DF} |
-    [\u{0300}-\u{036F}] |
-    [\u{0391}-\u{03A1}] |
-    [\u{03A3}-\u{03A9}] |
-    [\u{03B1}-\u{03C1}] |
-    [\u{03C3}-\u{03C9}] |
-    \u{0401} |
-    [\u{0410}-\u{044F}] |
-    \u{0451} |
-    \u{2010} |
-    [\u{2013}-\u{2016}] |
-    [\u{2018}-\u{2019}] |
-    [\u{201C}-\u{201D}] |
-    [\u{2020}-\u{2022}] |
-    [\u{2024}-\u{2027}] |
-    \u{2030} |
-    [\u{2032}-\u{2033}] |
-    \u{2035} |
-    \u{203B} |
-    \u{203E} |
-    \u{2074} |
-    \u{207F} |
-    [\u{2081}-\u{2084}] |
-    \u{20AC} |
-    \u{2103} |
-    \u{2105} |
-    \u{2109} |
-    \u{2113} |
-    \u{2116} |
-    [\u{2121}-\u{2122}] |
-    \u{2126} |
-    \u{212B} |
-    [\u{2153}-\u{2154}] |
-    [\u{215B}-\u{215E}] |
-    [\u{2160}-\u{216B}] |
-    [\u{2170}-\u{2179}] |
-    \u{2189} |
-    [\u{2190}-\u{2199}] |
-    [\u{21B8}-\u{21B9}] |
-    \u{21D2} |
-    \u{21D4} |
-    \u{21E7} |
-    \u{2200} |
-    [\u{2202}-\u{2203}] |
-    [\u{2207}-\u{2208}] |
-    \u{220B} |
-    \u{220F} |
-    \u{2211} |
-    \u{2215} |
-    \u{221A} |
-    [\u{221D}-\u{2220}] |
-    \u{2223} |
-    \u{2225} |
-    [\u{2227}-\u{222C}] |
-    \u{222E} |
-    [\u{2234}-\u{2237}] |
-    [\u{223C}-\u{223D}] |
-    \u{2248} |
-    \u{224C} |
-    \u{2252} |
-    [\u{2260}-\u{2261}] |
-    [\u{2264}-\u{2267}] |
-    [\u{226A}-\u{226B}] |
-    [\u{226E}-\u{226F}] |
-    [\u{2282}-\u{2283}] |
-    [\u{2286}-\u{2287}] |
-    \u{2295} |
-    \u{2299} |
-    \u{22A5} |
-    \u{22BF} |
-    \u{2312} |
-    [\u{2460}-\u{24E9}] |
-    [\u{24EB}-\u{254B}] |
-    [\u{2550}-\u{2573}] |
-    [\u{2580}-\u{258F}] |
-    [\u{2592}-\u{2595}] |
-    [\u{25A0}-\u{25A1}] |
-    [\u{25A3}-\u{25A9}] |
-    [\u{25B2}-\u{25B3}] |
-    [\u{25B6}-\u{25B7}] |
-    [\u{25BC}-\u (... truncated)

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

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