]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Speedups: avoid initialising constants in __init__, use frozenset instead of set
authorMenno Smits <menno@freshfoo.com>
Sat, 8 May 2010 08:59:08 +0000 (09:59 +0100)
committerMenno Smits <menno@freshfoo.com>
Sat, 8 May 2010 08:59:08 +0000 (09:59 +0100)
imapclient/response_lexer.py

index 532ae5c22fb4bf22d67147277e447f2085d21a29..bbf586348d58ac326cd52761e07eb9b661fd33ca 100644 (file)
@@ -39,11 +39,10 @@ class Lexer(object):
     CTRL_CHARS = ''.join([chr(ch) for ch in range(32)])
     SPECIALS = r' ()%"' + CTRL_CHARS
     ALL_CHARS = [chr(ch) for ch in range(256)]
-    NON_SPECIALS = [ch for ch in ALL_CHARS if ch not in SPECIALS]
+    NON_SPECIALS = frozenset([ch for ch in ALL_CHARS if ch not in SPECIALS])
+    WHITESPACE = frozenset(' \t\r\n')
 
     def __init__(self):
-        self.wordchars = set(self.NON_SPECIALS)
-        self.whitespace = set((' \t\r\n'))
         self.sources = None
         self.current_source = None
 
@@ -67,8 +66,8 @@ class Lexer(object):
         return quoted + token + quoted
 
     def read_token_stream(self, stream_i):
-        whitespace = self.whitespace
-        wordchars = self.wordchars
+        whitespace = self.WHITESPACE
+        wordchars = self.NON_SPECIALS
         parse_quote = self.parse_quote
 
         while True: