Cache nsIClassInfos for all Python classes. This works around a bug in

XPConnect that is soon to be fixed, but also allows us to take advantage
of the XPConnect caching, and to save rebuilding the same class info for
short-lived objects created repeatedly.

Not part of the build.
This commit is contained in:
markh%activestate.com 2001-09-19 00:25:31 +00:00
Родитель b5df3256fb
Коммит 686f97a24b
1 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -62,6 +62,22 @@ def _GetNominatedInterfaces(obj):
parent = parent.GetParent()
return real_ret
##
## ClassInfo support
##
## We cache class infos by class
class_info_cache = {}
def GetClassInfoForClass(klass):
# Note we do not store the wrapped object in the class - this would
# present us with shutdown problems (ie, needing to clear the
# cache), and also messes with lifetime issues.
ci = class_info_cache.get(klass)
if ci is None:
ci = DefaultClassInfo(klass)
class_info_cache[klass] = ci
return xpcom.server.WrapObject(ci, _xpcom.IID_nsIClassInfo, bWrapClient = 0)
class DefaultClassInfo:
_com_interfaces_ = _xpcom.IID_nsIClassInfo
def __init__(self, klass):
@ -117,7 +133,7 @@ class DefaultPolicy:
# Always support nsIClassInfo
if iid == _xpcom.IID_nsIClassInfo:
return xpcom.server.WrapObject(DefaultClassInfo(self._obj_.__class__), iid, bWrapClient = 0)
return GetClassInfoForClass(self._obj_.__class__)
# See if the instance has a QI
# use lower-case "_query_interface_" as win32com does, and it doesnt really matter.