reduced overhead in the scanner
authorStefan Behnel <scoder@users.berlios.de>
Mon, 15 Nov 2010 21:02:36 +0000 (22:02 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 15 Nov 2010 21:02:36 +0000 (22:02 +0100)
Cython/Plex/Scanners.py

index 02c36a6a8bec78ad5cad4381d7490c13f4245f26..d2fa468c6981aff13114ff2289c42fc926b24707 100644 (file)
@@ -8,11 +8,13 @@
 #=======================================================================
 
 import cython
-cython.declare(BOL=object, EOL=object, EOF=object)
+cython.declare(BOL=object, EOL=object, EOF=object, NOT_FOUND=object)
 
 import Errors
 from Regexps import BOL, EOL, EOF
 
+NOT_FOUND = object()
+
 class Scanner(object):
   """
   A Scanner is used to read tokens from a stream of characters
@@ -179,8 +181,8 @@ class Scanner(object):
       # End inlined self.save_for_backup()
       c = cur_char
       #new_state = state.new_state(c) #@slow
-      new_state = state.get(c, -1) #@fast
-      if new_state == -1: #@fast
+      new_state = state.get(c, NOT_FOUND) #@fast
+      if new_state is NOT_FOUND: #@fast
         new_state = c and state.get('else') #@fast
       if new_state:
         if trace: #TRACE#