diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-29 14:45:38 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-05-29 14:50:03 +0200 |
commit | 7190799ac75ba78f7f2b21860a884a1d2891952e (patch) | |
tree | 4380e3869db93019f9f11d9980b45d1c01457a07 | |
parent | b2afb1166090f19fb926f184da29f972793e1c37 (diff) | |
download | cython-7190799ac75ba78f7f2b21860a884a1d2891952e.tar.gz |
A bit more cythonisation in Machines.py and Transitions.py.
-rw-r--r-- | Cython/Plex/Machines.pxd | 12 | ||||
-rw-r--r-- | Cython/Plex/Machines.py | 15 | ||||
-rw-r--r-- | Cython/Plex/Transitions.py | 1 |
3 files changed, 21 insertions, 7 deletions
diff --git a/Cython/Plex/Machines.pxd b/Cython/Plex/Machines.pxd index 55a4f7b95..9235106b8 100644 --- a/Cython/Plex/Machines.pxd +++ b/Cython/Plex/Machines.pxd @@ -1,3 +1,15 @@ +cimport cython + +@cython.final +cdef class Node: + cdef readonly object transitions # TransitionMap + cdef readonly object action # Action + cdef public object epsilon_closure # dict + cdef readonly Py_ssize_t number + cdef readonly long action_priority + + +@cython.final cdef class FastMachine: cdef readonly dict initial_states cdef readonly dict new_state_template diff --git a/Cython/Plex/Machines.py b/Cython/Plex/Machines.py index f3a27e574..e55895b31 100644 --- a/Cython/Plex/Machines.py +++ b/Cython/Plex/Machines.py @@ -68,17 +68,15 @@ class Machine(object): class Node(object): """A state of an NFA or DFA.""" - transitions = None # TransitionMap - action = None # Action - action_priority = None # integer - number = 0 # for debug output - epsilon_closure = None # used by nfa_to_dfa() def __init__(self): # Preinitialise the list of empty transitions, because # the nfa-to-dfa algorithm needs it - self.transitions = TransitionMap() - self.action_priority = LOWEST_PRIORITY + self.transitions = TransitionMap() # TransitionMap + self.action_priority = LOWEST_PRIORITY # integer + self.action = None # Action + self.number = 0 # for debug output + self.epsilon_closure = None # used by nfa_to_dfa() def destroy(self): self.transitions = None @@ -127,6 +125,9 @@ class Node(object): def __lt__(self, other): return self.number < other.number + def __hash__(self): + return id(self) + class FastMachine(object): """ diff --git a/Cython/Plex/Transitions.py b/Cython/Plex/Transitions.py index 52d6d0a10..10ee513e7 100644 --- a/Cython/Plex/Transitions.py +++ b/Cython/Plex/Transitions.py @@ -153,6 +153,7 @@ class TransitionMap(object): map[hi:hi] = [code, map[hi - 1].copy()] return hi + @cython.ccall def get_special(self, event): """ Get state set for special event, adding a new entry if necessary. |