[merge] lazy regex

Martin Pool mbp at canonical.com
Tue Oct 10 06:53:13 BST 2006


On  9 Oct 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> The attached patch adds a new class and function, which allows us to
> create a lazy compiling regex class. It should be robust enough to
> actually replace re.compile() (and helper functions are provided to do
> just that).
> 
> The proxy object is designed to have a minimal amount of overhead after
> it has been activated. Which it does by setting the local attributes to
> the values of the compiled regex object.
> 
> I'd like to get this merged, since it has a very specific use when
> importing elementtree, which allows us to avoid 20-30ms of startup
> overhead for commands like 'status' and 'diff'. (I already avoid it for
> 'bzr rocks' because we don't need to do any xml parsing).

+1, if it really gives a performance imrpovement when installed
globally.

> +
> +
> +_real_re_compile = re.compile

I'm not sure if it's justified, but I feel I'd like an 

   assert _real_re_compile is not lazy_compile

> +
> +
> +class LazyRegex(object):
> +    """A proxy around a real regex, which won't compiled until accessed."""

"won't be compiled"


-- 
Martin




More information about the bazaar mailing list