Mercurial > genshi > mirror
changeset 717:0e8b92905741 experimental-match-fastpaths
a performance breakthrough - bring this branch inline with the bigtable benchmark by lazily creating ctxt._match_set in a way that doesn't barf
author | aflett |
---|---|
date | Tue, 08 Apr 2008 23:36:20 +0000 |
parents | b33c14a1f579 |
children | d143dd73789b |
files | genshi/template/base.py genshi/template/directives.py genshi/template/markup.py |
diffstat | 3 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/genshi/template/base.py +++ b/genshi/template/base.py @@ -25,7 +25,6 @@ from genshi.core import Attrs, Stream, StreamEventKind, START, TEXT, _ensure from genshi.input import ParseError -from genshi.template.match import MatchSet __all__ = ['Context', 'Template', 'TemplateError', 'TemplateRuntimeError', 'TemplateSyntaxError', 'BadDirectiveError'] @@ -137,7 +136,7 @@ self.frames = deque([data]) self.pop = self.frames.popleft self.push = self.frames.appendleft - self._match_set = MatchSet() + self._match_set = None self._choice_stack = [] # Helper functions for use in expressions
--- a/genshi/template/directives.py +++ b/genshi/template/directives.py @@ -457,6 +457,10 @@ attach = classmethod(attach) def __call__(self, stream, directives, ctxt, **vars): + # create this lazily because it's much faster to check 'if + # match_set' when match_set is None + if ctxt._match_set is None: + ctxt._match_set = MatchSet() ctxt._match_set.add((self.path.test(ignore_context=True), self.path, list(stream), self.hints, self.namespaces, directives))
--- a/genshi/template/markup.py +++ b/genshi/template/markup.py @@ -229,9 +229,6 @@ """Internal stream filter that applies any defined match templates to the stream. """ - if match_set is None: - match_set = ctxt._match_set - tail = [] def _strip(stream): depth = 1 @@ -249,6 +246,11 @@ for event in stream: + # we may have discovered a py:match while processing the + # stream.. so keep checking for ctxt._match_set + if match_set is None: + match_set = ctxt._match_set + # We (currently) only care about start and end events for matching # We might care about namespace events in the future, though if not match_set or (event[0] is not START and