[pywin32-checkins] /hgroot/pywin32/pywin32: A couple of optimizations for where an ...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-13 22:27:22
|
changeset 7db23de8daa7 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=7db23de8daa7 summary: A couple of optimizations for where an object is already PyIDispatch diffstat: com/win32com/client/dynamic.py | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diffs (47 lines): diff -r 2ad7e595084e -r 7db23de8daa7 com/win32com/client/dynamic.py --- a/com/win32com/client/dynamic.py Mon Aug 13 15:04:21 2012 -0400 +++ b/com/win32com/client/dynamic.py Mon Aug 13 18:24:08 2012 -0400 @@ -71,13 +71,19 @@ MakeMethod = types.MethodType # all args used in py2k. # get the type objects for IDispatch and IUnknown -dispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] -iunkType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown] +PyIDispatchType = pythoncom.TypeIIDs[pythoncom.IID_IDispatch] +PyIUnknownType = pythoncom.TypeIIDs[pythoncom.IID_IUnknown] -_GoodDispatchTypes=(str, IIDType, unicode) +if py3k: + _GoodDispatchTypes=(str, IIDType) +else: + _GoodDispatchTypes=(str, IIDType, unicode) _defaultDispatchItem=build.DispatchItem def _GetGoodDispatch(IDispatch, clsctx = pythoncom.CLSCTX_SERVER): + # quick return for most common case + if isinstance(IDispatch, PyIDispatchType): + return IDispatch if isinstance(IDispatch, _GoodDispatchTypes): try: IDispatch = pythoncom.connect(IDispatch) @@ -282,15 +288,15 @@ return Dispatch(ob, userName) def _get_good_single_object_(self,ob,userName = None, ReturnCLSID=None): - if iunkType==type(ob): + if isinstance(ob, PyIDispatchType): + # make a new instance of (probably this) class. + return self._wrap_dispatch_(ob, userName, ReturnCLSID) + if isinstance(ob, PyIUnknownType): try: ob = ob.QueryInterface(pythoncom.IID_IDispatch) - # If this works, we then enter the "is dispatch" test below. except pythoncom.com_error: # It is an IUnknown, but not an IDispatch, so just let it through. - pass - if dispatchType==type(ob): - # make a new instance of (probably this) class. + return ob return self._wrap_dispatch_(ob, userName, ReturnCLSID) return ob |