[Python-checkins] python/dist/src/Lib pickle.py,1.142,1.143

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
2003年2月03日 11:46:58 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv2565
Modified Files:
	pickle.py 
Log Message:
_slotnames(): this is a fairly expensive calculation. Cache the
outcome as __slotnames__ on the class. (Like __slots__, it's not safe
to ask for this as an attribute -- you must look for it in the
specific class's __dict__. But it must be set using attribute
notation, because __dict__ is a read-only proxy.)
Index: pickle.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pickle.py,v
retrieving revision 1.142
retrieving revision 1.143
diff -C2 -d -r1.142 -r1.143
*** pickle.py	3 Feb 2003 18:10:09 -0000	1.142
--- pickle.py	3 Feb 2003 19:46:54 -0000	1.143
***************
*** 877,887 ****
 defined.)
 """
! if not hasattr(cls, "__slots__"):
! return []
 names = []
! for c in cls.__mro__:
! if "__slots__" in c.__dict__:
! names += [name for name in c.__dict__["__slots__"]
! if name not in ("__dict__", "__weakref__")]
 return names
 
--- 877,904 ----
 defined.)
 """
! 
! # Get the value from a cache in the class if possible
! names = cls.__dict__.get("__slotnames__")
! if names is not None:
! return names
! 
! # Not cached -- calculate the value
 names = []
! if not hasattr(cls, "__slots__"):
! # This class has no slots
! pass
! else:
! # Slots found -- gather slot names from all base classes
! for c in cls.__mro__:
! if "__slots__" in c.__dict__:
! names += [name for name in c.__dict__["__slots__"]
! if name not in ("__dict__", "__weakref__")]
! 
! # Cache the outcome in the class if at all possible
! try:
! cls.__slotnames__ = names
! except:
! pass # But don't die if we can't
! 
 return names
 

AltStyle によって変換されたページ (->オリジナル) /