Changeset 153:a8b8beb4b0dd

Show
Ignore:
Timestamp:
08/05/10 09:59:08 (21 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Speedups: avoid initialising constants in init, use frozenset instead of set

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/response_lexer.py

    r152 r153  
    4040    SPECIALS = r' ()%"' + CTRL_CHARS 
    4141    ALL_CHARS = [chr(ch) for ch in range(256)] 
    42     NON_SPECIALS = [ch for ch in ALL_CHARS if ch not in SPECIALS] 
     42    NON_SPECIALS = frozenset([ch for ch in ALL_CHARS if ch not in SPECIALS]) 
     43    WHITESPACE = frozenset(' \t\r\n') 
    4344 
    4445    def __init__(self): 
    45         self.wordchars = set(self.NON_SPECIALS) 
    46         self.whitespace = set((' \t\r\n')) 
    4746        self.sources = None 
    4847        self.current_source = None 
     
    6867 
    6968    def read_token_stream(self, stream_i): 
    70         whitespace = self.whitespace 
    71         wordchars = self.wordchars 
     69        whitespace = self.WHITESPACE 
     70        wordchars = self.NON_SPECIALS 
    7271        parse_quote = self.parse_quote 
    7372