Issues

Issue #159 resolved

don't need to copy __builtins__ into data

Mike Bayer
repo owner created an issue

someone pointed this out on the list. The copy we do from builtins means templates without a lot of variables are going to be disproportionately slow. We can shift to a "check dict then builtins" approach, possibly using some newer Python dictionary features (i.e. missing):

  1. !diff diff -r 6779081b32cfb237062da8bc623a27d47301ce4c mako/runtime.py --- a/mako/runtime.py Wed Jan 19 10:33:00 2011 -0500 +++ b/mako/runtime.py Thu Feb 10 17:20:58 2011 -0500 @@ -22,12 +22,7 @@ def init(self, buffer, data): self._buffer_stack = [buffer]

- # original data, minus the builtins - self._orig = data - - # the context data which includes builtins - self._data = builtin.dict.copy() - self._data.update(data) + self._data = data self._kwargs = data.copy() self._with_template = None self._outputting_as_unicode = None @@ -75,7 +70,10 @@ return self._data.keys()

def getitem(self, key): - return self._data[key] + if key in self._data: + return self._data[key] + else: + return builtins[key]

def _push_writer(self): """push a capturing buffer onto this Context and return @@ -107,7 +105,9 @@ def get(self, key, default=None): """Return a value from this :class:`.Context`."""

- return self._data.get(key, default) + return self._data.get(key, + builtins.get(key, default) + )

def write(self, string): """Write a string to this :class:`.Context` object's @@ -124,7 +124,6 @@ c = Context.new(Context) c._buffer_stack = self._buffer_stack c._data = self._data.copy() - c._orig = self._orig c._kwargs = self._kwargs c._with_template = self._with_template c._outputting_as_unicode = self._outputting_as_unicode @@ -499,7 +498,7 @@ (callable_, ctx) = _populate_self_namespace( context._clean_inheritance_tokens(), template) - callable_(ctx, _kwargs_for_include(callable_, context._orig, kwargs)) + callable_(ctx, _kwargs_for_include(callable_, context._data, kwargs))

def _inherit_from(context, uri, calling_uri): """called by the _inherit method in template modules to set diff -r 6779081b32cfb237062da8bc623a27d47301ce4c setup.cfg --- a/setup.cfg Wed Jan 19 10:33:00 2011 -0500 +++ b/setup.cfg Thu Feb 10 17:20:58 2011 -0500 @@ -1,2 +1,5 @@ [egg_info] tag_build = dev + +[nosetests] +where = test

Comments (1)

  1. Log in to comment