Magic Optimisation

Tomasz Lisowski list at notmyisp.pl
Mon Sep 5 10:20:13 CEST 2005


simonwittber at gmail.com napisał(a):
>>    def loop(self):
>>        self_pool = self.pool
>>        self_call_exit_funcs = self.call_exit_funcs
>>        self_pool_popleft = self.pool.popleft
>>        self_pool_append = self.pool.append
>>        check = self.pool.__len__
>>        while check() > 0:
>>            task = self_pool_popleft()
>>            try:
>>                task.next()
>>            except StopIteration:
>>                self_call_exit_funcs(task)
>>                return
>>            self_pool_append(task)
> 
> 
> Stupid me. the 'return' statement above should be 'continue'. Sorry for
> the confusion.
> 

Then you can avoid continue by writing:

         while check() > 0:
             task = self_pool_popleft()
             try:
                 task.next()
             except StopIteration:
                 self_call_exit_funcs(task)
             else:
                 self_pool_append(task)

Tomasz Lisowski



More information about the Python-list mailing list