comparison genshi/template/directives.py @ 704:422d0607ba85 experimental-match-fastpaths

further performance improvements to MatchSet functionality - factor out MatchSet's State so that we dont' have to keep copying over the state every time we create a new child MatchSet. Also fixes a bug where we could get duplicate match indexes when a new match is created while evaluating an existing match Also, try to be lazy about creating the first MatchSet so that we don't hurt bigtable performance (i.e. when there are no py:matches in play at all)
author aflett
date Fri, 04 Apr 2008 16:57:27 +0000
parents af57b12e3dd2
children 2a7a19861a89
comparison
equal deleted inserted replaced
703:af57b12e3dd2 704:422d0607ba85
24 from genshi.template.base import TemplateRuntimeError, TemplateSyntaxError, \ 24 from genshi.template.base import TemplateRuntimeError, TemplateSyntaxError, \
25 EXPR, _apply_directives, _eval_expr, \ 25 EXPR, _apply_directives, _eval_expr, \
26 _exec_suite 26 _exec_suite
27 from genshi.template.eval import Expression, Suite, ExpressionASTTransformer, \ 27 from genshi.template.eval import Expression, Suite, ExpressionASTTransformer, \
28 _parse 28 _parse
29 from genshi.template.match import MatchSet
29 30
30 __all__ = ['AttrsDirective', 'ChooseDirective', 'ContentDirective', 31 __all__ = ['AttrsDirective', 'ChooseDirective', 'ContentDirective',
31 'DefDirective', 'ForDirective', 'IfDirective', 'MatchDirective', 32 'DefDirective', 'ForDirective', 'IfDirective', 'MatchDirective',
32 'OtherwiseDirective', 'ReplaceDirective', 'StripDirective', 33 'OtherwiseDirective', 'ReplaceDirective', 'StripDirective',
33 'WhenDirective', 'WithDirective'] 34 'WhenDirective', 'WithDirective']
454 return cls(value, template, frozenset(hints), namespaces, *pos[1:]), \ 455 return cls(value, template, frozenset(hints), namespaces, *pos[1:]), \
455 stream 456 stream
456 attach = classmethod(attach) 457 attach = classmethod(attach)
457 458
458 def __call__(self, stream, directives, ctxt, **vars): 459 def __call__(self, stream, directives, ctxt, **vars):
460 if ctx._match_set is None:
461 # lazily create MatchSet so that it doesn't burden the
462 # _match filter when there are no py:matches defined.
463 ctx._match_set = MatchSet()
459 ctxt._match_set.add((self.path.test(ignore_context=True), 464 ctxt._match_set.add((self.path.test(ignore_context=True),
460 self.path, list(stream), self.hints, 465 self.path, list(stream), self.hints,
461 self.namespaces, directives)) 466 self.namespaces, directives))
462 return [] 467 return []
463 468
Copyright (C) 2012-2017 Edgewall Software