Skip to content

Commit ab49138

Browse files
committed
Speedup C scanner (reordering of token rules).
1 parent d6ac355 commit ab49138

File tree

1 file changed

+7
-7
lines changed
  • lib/coderay/scanners

1 file changed

+7
-7
lines changed

lib/coderay/scanners/c.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ def scan_tokens encoder, options
6565
elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
6666
encoder.text_token match, :comment
6767

68-
elsif match = scan(/ \# \s* if \s* 0 /x)
69-
match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
70-
encoder.text_token match, :comment
71-
7268
elsif match = scan(/ [-+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
7369
label_expected = match =~ /[;\{\}]/
7470
if case_expected
@@ -93,9 +89,6 @@ def scan_tokens encoder, options
9389
end
9490
encoder.text_token match, kind
9591

96-
elsif match = scan(/\$/)
97-
encoder.text_token match, :ident
98-
9992
elsif match = scan(/L?"/)
10093
encoder.begin_group :string
10194
if match[0] == ?L
@@ -105,6 +98,10 @@ def scan_tokens encoder, options
10598
encoder.text_token match, :delimiter
10699
state = :string
107100

101+
elsif match = scan(/ \# \s* if \s* 0 /x)
102+
match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
103+
encoder.text_token match, :comment
104+
108105
elsif match = scan(/#[ \t]*(\w*)/)
109106
encoder.text_token match, :preprocessor
110107
in_preproc_line = true
@@ -115,6 +112,9 @@ def scan_tokens encoder, options
115112
label_expected = false
116113
encoder.text_token match, :char
117114

115+
elsif match = scan(/\$/)
116+
encoder.text_token match, :ident
117+
118118
elsif match = scan(/0[xX][0-9A-Fa-f]+/)
119119
label_expected = false
120120
encoder.text_token match, :hex

0 commit comments

Comments
 (0)