Magic Optimisation

Paul McGuire ptmcg at austin.rr.com
Mon Sep 5 00:00:33 EDT 2005


This isn't much prettier, but what if you extract the try-except
overhead out from the while loop?  You only expect the exception to
fire one time, at the end of the list.  You can also eliminate any
localization of variables for calls that are not called in the loop,
such as self_pool (which does not seem to be used at all), and
self_call_exit_funcs.

-- Paul

    def loop(self):
        self_pool_popleft = self.pool.popleft
        self_pool_append = self.pool.append
        check = self.pool.__len__
        try:
            while check() > 0:
                task = self_pool_popleft()
                task.next()
                self_pool_append(task)
        except StopIteration:
            self.call_exit_funcs(task) 
            return




More information about the Python-list mailing list