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

ruby-changes:55858

From: Takashi <ko1@a...>
Date: Mon, 27 May 2019 03:26:25 +0900 (JST)
Subject: [ruby-changes:55858] Takashi Kokubun: 7597f7ecb1 (trunk): Simplify lexer state matching in #dispatch_seq

https://git.ruby-lang.org/ruby.git/commit/?id=7597f7ecb1

From 7597f7ecb18ae537002391f9feb7f0e689d3b87b Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sun, 26 May 2019 11:24:52 -0700
Subject: Simplify lexer state matching in #dispatch_seq

for improving readability of the condition. It may be slightly faster, or may not.

diff --git a/lib/irb/color.rb b/lib/irb/color.rb
index 694835c..da8791b 100644
--- a/lib/irb/color.rb
+++ b/lib/irb/color.rb
@@ -20,36 +20,40 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L20
     }
     private_constant :TOKEN_KEYWORDS
 
+    # A constant of all-bit 1 to match any Ripper's state in #dispatch_seq
+    ALL = -1
+    private_constant :ALL
+
     begin
       # Following pry's colors where possible, but sometimes having a compromise like making
       # backtick and regexp as red (string's color, because they're sharing tokens).
       TOKEN_SEQ_EXPRS = {
-        on_CHAR:            [[BLUE, BOLD],            :all],
-        on_backtick:        [[RED],                   :all],
-        on_const:           [[BLUE, BOLD, UNDERLINE], :all],
-        on_comment:         [[BLUE, BOLD],            :all],
-        on_embexpr_beg:     [[RED],                   :all],
-        on_embexpr_end:     [[RED],                   :all],
-        on_embvar:          [[RED],                   :all],
-        on_float:           [[MAGENTA, BOLD],         :all],
-        on_heredoc_beg:     [[RED],                   :all],
-        on_heredoc_end:     [[RED],                   :all],
+        on_CHAR:            [[BLUE, BOLD],            ALL],
+        on_backtick:        [[RED],                   ALL],
+        on_const:           [[BLUE, BOLD, UNDERLINE], ALL],
+        on_comment:         [[BLUE, BOLD],            ALL],
+        on_embexpr_beg:     [[RED],                   ALL],
+        on_embexpr_end:     [[RED],                   ALL],
+        on_embvar:          [[RED],                   ALL],
+        on_float:           [[MAGENTA, BOLD],         ALL],
+        on_heredoc_beg:     [[RED],                   ALL],
+        on_heredoc_end:     [[RED],                   ALL],
         on_ident:           [[BLUE, BOLD],            Ripper::EXPR_ENDFN],
-        on_imaginary:       [[BLUE, BOLD],            :all],
-        on_int:             [[BLUE, BOLD],            :all],
-        on_kw:              [[GREEN],                 :all],
-        on_label:           [[MAGENTA],               :all],
-        on_label_end:       [[RED],                   :all],
-        on_qsymbols_beg:    [[RED],                   :all],
-        on_qwords_beg:      [[RED],                   :all],
-        on_rational:        [[BLUE, BOLD],            :all],
-        on_regexp_beg:      [[RED, BOLD],             :all],
-        on_regexp_end:      [[RED, BOLD],             :all],
-        on_symbeg:          [[YELLOW],                :all],
-        on_tstring_beg:     [[RED],                   :all],
-        on_tstring_content: [[RED],                   :all],
-        on_tstring_end:     [[RED],                   :all],
-        on_words_beg:       [[RED],                   :all],
+        on_imaginary:       [[BLUE, BOLD],            ALL],
+        on_int:             [[BLUE, BOLD],            ALL],
+        on_kw:              [[GREEN],                 ALL],
+        on_label:           [[MAGENTA],               ALL],
+        on_label_end:       [[RED],                   ALL],
+        on_qsymbols_beg:    [[RED],                   ALL],
+        on_qwords_beg:      [[RED],                   ALL],
+        on_rational:        [[BLUE, BOLD],            ALL],
+        on_regexp_beg:      [[RED, BOLD],             ALL],
+        on_regexp_end:      [[RED, BOLD],             ALL],
+        on_symbeg:          [[YELLOW],                ALL],
+        on_tstring_beg:     [[RED],                   ALL],
+        on_tstring_content: [[RED],                   ALL],
+        on_tstring_end:     [[RED],                   ALL],
+        on_words_beg:       [[RED],                   ALL],
       }
     rescue NameError
       # Give up highlighting Ripper-incompatible older Ruby
@@ -121,7 +125,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L125
           [YELLOW]
         elsif TOKEN_KEYWORDS.fetch(token, []).include?(str)
           [CYAN, BOLD]
-        elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; exprs == :all || (exprs != nil && (expr & exprs) != 0))
+        elsif (seq, exprs = TOKEN_SEQ_EXPRS[token]; (expr & (exprs || 0)) != 0)
           seq
         else
           nil
-- 
cgit v0.10.2


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

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