diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2009-06-02 14:44:19 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2009-06-02 14:44:19 +0000 |
| commit | c341fa6d1d0aa73691cffb7dd1c8d21c28073ac9 (patch) | |
| tree | cbf8655d175e706546f8f37e611ffbf3bab991bf /docutils/statemachine.py | |
| parent | 83a493ac7248eabc3b6e290385bfc79ccfcd72c4 (diff) | |
| download | docutils-c341fa6d1d0aa73691cffb7dd1c8d21c28073ac9.tar.gz | |
Using a cache in the parsers state machine.
Patch sent by Naoki INADA to docutils-devel giving around 25 % speedup.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@5968 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/statemachine.py')
| -rw-r--r-- | docutils/statemachine.py | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/docutils/statemachine.py b/docutils/statemachine.py index 877c8f82d..83eec3689 100644 --- a/docutils/statemachine.py +++ b/docutils/statemachine.py @@ -176,7 +176,7 @@ class StateMachine: self.states = None def run(self, input_lines, input_offset=0, context=None, - input_source=None): + input_source=None, initial_state=None): """ Run the state machine on `input_lines`. Return results (a list). @@ -196,6 +196,7 @@ class StateMachine: of the file. - `context`: application-specific storage. - `input_source`: name or path of source of `input_lines`. + - `initial_state`: name of initial state. """ self.runtime_init() if isinstance(input_lines, StringList): @@ -204,7 +205,7 @@ class StateMachine: self.input_lines = StringList(input_lines, source=input_source) self.input_offset = input_offset self.line_offset = -1 - self.current_state = self.initial_state + self.current_state = initial_state or self.initial_state if self.debug: print >>sys.stderr, ( '\nStateMachine.run: input_lines (line_offset=%s):\n| %s' @@ -410,7 +411,7 @@ class StateMachine: % (state.__class__.__name__, transitions)) for name in transitions: pattern, method, next_state = state.transitions[name] - match = self.match(pattern) + match = pattern.match(self.line) if match: if self.debug: print >>sys.stderr, ( @@ -425,14 +426,6 @@ class StateMachine: % state.__class__.__name__) return state.no_match(context, transitions) - def match(self, pattern): - """ - Return the result of a regular expression match. - - Parameter `pattern`: an `re` compiled regular expression. - """ - return pattern.match(self.line) - def add_state(self, state_class): """ Initialize & add a `state_class` (`State` subclass) object. |
