Skip to content

Commit 252f963

Browse files
committed
Combine whitespace and comment regexes.
This shaves off another percent or two of runtime.
1 parent 5a6489b commit 252f963

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/matplotlib/type1font.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ def _split(self, data):
135135

136136
return data[:len1], binary, data[idx+1:]
137137

138-
_whitespace_re = re.compile(br'[\0\t\r\014\n ]+')
138+
_whitespace_or_comment_re = re.compile(br'[\0\t\r\014\n ]+|%[^\r\n\v]*')
139139
_token_re = re.compile(br'/{0,2}[^]\0\t\r\v\n ()<>{}/%[]+')
140-
_comment_re = re.compile(br'%[^\r\n\v]*')
141140
_instring_re = re.compile(br'[()\\]')
142141

143142
@classmethod
@@ -148,8 +147,7 @@ def _tokens(cls, text):
148147
"""
149148
pos = 0
150149
while pos < len(text):
151-
match = (cls._comment_re.match(text, pos) or
152-
cls._whitespace_re.match(text, pos))
150+
match = cls._whitespace_or_comment_re.match(text, pos)
153151
if match:
154152
yield (_TokenType.whitespace, match.group())
155153
pos = match.end()

0 commit comments

Comments
 (0)