[PATCH 0 of 1] debugcommands.py

Luke Plant L.Plant.98 at cantab.net
Wed May 11 12:44:03 CDT 2011


On 11/05/11 10:44, Adrian Buehlmann wrote:

> Or (after having pondered http://www.artima.com/weblogs/viewpost.jsp?thread=240845 ):
> 
> table = {}
> 
> class command(object):
>     def __init__(self, name, options, synopsis):
>         self.name = name
>         self.options = options
>         self.synopsis = synopsis
> 
>     def __call__(self, func):
>         table[self.name] = (func, self.options, self.synopsis)
> 

If module load time is an issue, this is going to be much slower than
the simple function-based decorator, due to:

 - creation of an instance instead of a function
 - storing and retrieving data on the instance

In terms of performance after that, it's not affected in either case,
because the original function is returned, and not a wrapper. Most of
the cases on Bruce Eckel's post deal with wrappers being returned, which
is not necessary in this case.

Luke

-- 
Parenthetical remarks (however relevant) are unnecessary

Luke Plant || http://lukeplant.me.uk/


More information about the Mercurial-devel mailing list