# HG changeset patch # User Christian Ebert # Date 1171034182 -3600 # Node ID 5e9d6c57d679fef38e84111353c2170b05545036 # Parent a4c748fc7e0044b125c0388817fb45d587696b77 Parse templates at kwtemplater init for less overhead in matchfunction diff -r a4c748fc7e00 -r 5e9d6c57d679 hgkw/keyword.py --- a/hgkw/keyword.py Fri Feb 09 16:13:51 2007 +0100 +++ b/hgkw/keyword.py Fri Feb 09 16:16:22 2007 +0100 @@ -105,7 +105,13 @@ def __init__(self, ui, repo): self.ui = ui self.repo = repo - self.templates = dict(ui.configitems('keywordmaps')) or deftemplates + templates = dict(ui.configitems('keywordmaps')) + if templates: + # parse templates here for less overhead in kwsub matchfunc + for k in templates.keys(): + templates[k] = templater.parsestring(templates[k], + quoted=False) + self.templates = templates or deftemplates self.re_kw = re.compile(r'\$(%s)[^$]*?\$' % '|'.join(re.escape(k) for k in self.templates.keys())) templater.common_filters['utcdate'] = utcdate @@ -120,8 +126,7 @@ def kwsub(self, mobj, path, node): '''Substitutes keyword using corresponding template.''' kw = mobj.group(1) - template = templater.parsestring(self.templates[kw], quoted=False) - self.t.use_template(template) + self.t.use_template(self.templates[kw]) self.ui.pushbuffer() self.t.show(changenode=node, root=self.repo.root, file=path) keywordsub = templater.firstline(self.ui.popbuffer())