[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Speed *triples* by changing 'apply(f, args)' to 'f(*args)'
Gerrit Holl schreef op woensdag 5 maart om 15:38:57 +0000:
> Pete Shinners schreef op woensdag 5 maart om 08:13:11 +0000:
> > Gerrit Holl wrote:
> > >Then I changed in sprite.py:311, apply(f, args) to f(*args).
> > >Framespeed tripled:
> >
> > i'm curious about the 'warning' you are getting. can you run with the
> > "-W all" flags under python, that should print all the warnings you are
> > getting. my version currently runs the same speed either way, but i am
> > not seeing any kind of warnings getting triggered. i'm also checking
> > against 2.3a2
>
> Ah. I didn't know about '-W all'. I get:
> /usr/local/lib/python2.3/site-packages/pygame/sprite.py:319: PendingDeprecationWarning: use func(*args, **kwargs) instead of apply(func, args, kwargs)
I propose the following patch (attached as well):
Index: lib/sprite.py
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/pygame/lib/sprite.py,v
retrieving revision 1.20
diff -c -r1.20 sprite.py
*** lib/sprite.py 28 Feb 2003 17:48:58 -0000 1.20
--- lib/sprite.py 5 Mar 2003 14:45:57 -0000
***************
*** 314,326 ****
calls the update method for all sprites in the group.
passes all arguments are to the Sprite update function."""
! if args:
! a=apply
for s in self.spritedict.keys():
! a(s.update, args)
else:
! for s in self.spritedict.keys():
! s.update()
def __nonzero__(self):
--- 314,329 ----
calls the update method for all sprites in the group.
passes all arguments are to the Sprite update function."""
! if sys.hexversion >= 0x20000a1:
for s in self.spritedict.keys():
! s.update(*args)
else:
! if args:
! for s in self.spritedict.keys():
! a(s.update, args)
! else:
! for s in self.spritedict.keys():
! s.update()
def __nonzero__(self):
BTW, I am running the latest CVS, maybe that's the difference.
yours,
Gerrit.
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
? Setup
? build
? config.pyc
? config_unix.pyc
? examples/aliens2.py
? examples/chimp2.py
? examples/uberball2.py
? lib/sprite.pyc
Index: lib/sprite.py
===================================================================
RCS file: /home/cvspsrv/cvsroot/games/pygame/lib/sprite.py,v
retrieving revision 1.20
diff -c -r1.20 sprite.py
*** lib/sprite.py 28 Feb 2003 17:48:58 -0000 1.20
--- lib/sprite.py 5 Mar 2003 14:45:57 -0000
***************
*** 314,326 ****
calls the update method for all sprites in the group.
passes all arguments are to the Sprite update function."""
! if args:
! a=apply
for s in self.spritedict.keys():
! a(s.update, args)
else:
! for s in self.spritedict.keys():
! s.update()
def __nonzero__(self):
--- 314,329 ----
calls the update method for all sprites in the group.
passes all arguments are to the Sprite update function."""
! if sys.hexversion >= 0x20000a1:
for s in self.spritedict.keys():
! s.update(*args)
else:
! if args:
! for s in self.spritedict.keys():
! a(s.update, args)
! else:
! for s in self.spritedict.keys():
! s.update()
def __nonzero__(self):