Mercurial > fife-parpg
diff engine/extensions/pychan/tools.py @ 330:33dd55160a9d
* Added a new method Widget.getNamedChildren
* Made the distribute and mapEvents methods (a whole lot) faster.
* Added a new (internal) attribute to Widget (has_name)
* Added a small decorator for profiling rarely called functions.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 24 Aug 2009 11:45:28 +0000 |
parents | 54bfd1015b35 |
children | 48c99636453e |
line wrap: on
line diff
--- a/engine/extensions/pychan/tools.py Mon Aug 24 10:01:06 2009 +0000 +++ b/engine/extensions/pychan/tools.py Mon Aug 24 11:45:28 2009 +0000 @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- coding: utf-8 -*- """ Functional utilities designed for pychan use cases. @@ -121,6 +121,24 @@ applyOnlySuitable(callback, event=event, widget=widget) return chain_callback +def repeatALot(n = 1000): + """ + Internal decorator used to profile some pychan functions. + Only use with functions without side-effect. + + Usage:: + @repeatALot(n=10000) + def findChild(self,**kwargs): + ... + """ + def wrap_f(f): + def new_f(*args,**kwargs): + for i in xrange(n): + f(*args,**kwargs) + return f(*args,**kwargs) + return new_f + return wrap_f + def this_is_deprecated(func,message=None): if message is None: message = repr(func)