From f466bcdf46c4400debdacf662e472c48e7bad857 Mon Sep 17 00:00:00 2001 From: "markh%activestate.com" Date: Wed, 19 Sep 2001 00:25:31 +0000 Subject: [PATCH] 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. git-svn-id: svn://10.0.0.236/trunk@103159 18797224-902f-48f8-a5cc-f745e15eee43 --- .../extensions/python/xpcom/server/policy.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mozilla/extensions/python/xpcom/server/policy.py b/mozilla/extensions/python/xpcom/server/policy.py index d041849f738..58145673ff5 100644 --- a/mozilla/extensions/python/xpcom/server/policy.py +++ b/mozilla/extensions/python/xpcom/server/policy.py @@ -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.