From 13fb2739bfa6ffe9f8b07a725be5b55157c720c3 Mon Sep 17 00:00:00 2001 From: Nikita Nemkin Date: Mon, 13 May 2019 17:57:43 +0500 Subject: Bug 547475 - [Win32] Remove redundant COM interface vtables In case of COM interface inheritance, derived interface vtable (COMObject instance) can be reused as a base interface vtable. This reuse doesn't affect object behavior in any way. Affected interfaces and their bases: * IAccessible2 : IAccessible * IAccessibleHyperlink : IAccessibleAction * IAccessibleHypertext : IAccessibleText * IEnumFORMATETC : IUnknown * IDIOleClientSite : IUnknown * IPropertyNotifySink : IUnknown Change-Id: If6b3bcdbe1515d75d561e5e7dca9d8cb6f8a93ba Signed-off-by: Nikita Nemkin --- .../org/eclipse/swt/accessibility/Accessible.java | 207 ++------------------- .../org/eclipse/swt/dnd/OleEnumFORMATETC.java | 22 +-- .../org/eclipse/swt/ole/win32/OleClientSite.java | 25 +-- .../win32/org/eclipse/swt/ole/win32/OleFrame.java | 15 -- .../swt/ole/win32/OlePropertyChangeSink.java | 20 +- 5 files changed, 20 insertions(+), 269 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/win32/org/eclipse/swt/accessibility/Accessible.java b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/win32/org/eclipse/swt/accessibility/Accessible.java index e895030392..8e87fab0c9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Accessibility/win32/org/eclipse/swt/accessibility/Accessible.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Accessibility/win32/org/eclipse/swt/accessibility/Accessible.java @@ -58,10 +58,10 @@ public class Accessible { static int UniqueID = -0x10; int refCount = 0, enumIndex = 0; Runnable timer; - COMObject objIAccessible, objIEnumVARIANT, objIServiceProvider, objIAccessible2, objIAccessibleAction, + COMObject objIAccessible, objIEnumVARIANT, objIServiceProvider, objIAccessibleApplication, /*objIAccessibleComponent,*/ objIAccessibleEditableText, objIAccessibleHyperlink, objIAccessibleHypertext, /*objIAccessibleImage,*/ objIAccessibleTable2, objIAccessibleTableCell, - objIAccessibleText, objIAccessibleValue; /* objIAccessibleRelation is defined in Relation class */ + objIAccessibleValue; /* objIAccessibleRelation is defined in Relation class */ IAccessible iaccessible; List accessibleListeners; List accessibleControlListeners; @@ -149,7 +149,7 @@ public class Accessible { } void createIAccessible() { - objIAccessible = new COMObject(new int[] {2,0,0,1,3,5,8,1,1,2,2,2,2,2,2,2,3,2,1,1,2,2,5,3,3,1,2,2}) { + objIAccessible = new COMObject(new int[] {2,0,0,/*IA>>*/1,3,5,8,1,1,2,2,2,2,2,2,2,3,2,1,1,2,2,5,3,3,1,2,2,/*<>*/1,3,5,8,1,1,2,2,2,2,2,2,2,3,2,1,1,2,2,5,3,3,1,2,2,/*< 0 || accessibleTextExtendedListenersSize() > 0 || accessibleValueListenersSize() > 0 || accessibleControlListenersSize() > 0 || getRelationCount() > 0 || (control instanceof Button && ((control.getStyle() & SWT.RADIO) != 0)) || (control instanceof Composite)) { - if (objIAccessible2 == null) createIAccessible2(); - OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessible2.getAddress() }, C.PTR_SIZEOF); + // NOTE: IAccessible2 vtable is shared with IAccessible + if (objIAccessible == null) createIAccessible(); + OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessible.getAddress() }, C.PTR_SIZEOF); AddRef(); return COM.S_OK; } @@ -2055,8 +1876,9 @@ public class Accessible { if (COM.IsEqualGUID(guid, COM.IIDIAccessibleAction)) { if (accessibleActionListenersSize() > 0) { - if (objIAccessibleAction == null) createIAccessibleAction(); - OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessibleAction.getAddress() }, C.PTR_SIZEOF); + // NOTE: IAccessibleAction vtable is shared with IAccessibleHyperlink + if (objIAccessibleHyperlink == null) createIAccessibleHyperlink(); + OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessibleHyperlink.getAddress() }, C.PTR_SIZEOF); AddRef(); return COM.S_OK; } @@ -2149,8 +1971,9 @@ public class Accessible { if (COM.IsEqualGUID(guid, COM.IIDIAccessibleText)) { if (accessibleTextExtendedListenersSize() > 0 || accessibleAttributeListenersSize() > 0) { - if (objIAccessibleText == null) createIAccessibleText(); - OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessibleText.getAddress() }, C.PTR_SIZEOF); + // NOTE: IAccessibleText vtable is shared with IAccessibleHypertext + if (objIAccessibleHypertext == null) createIAccessibleHypertext(); + OS.MoveMemory(ppvObject, new long /*int*/[] { objIAccessibleHypertext.getAddress() }, C.PTR_SIZEOF); AddRef(); return COM.S_OK; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/OleEnumFORMATETC.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/OleEnumFORMATETC.java index a8366cd0d9..dce84b050b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/OleEnumFORMATETC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/OleEnumFORMATETC.java @@ -19,7 +19,6 @@ import org.eclipse.swt.internal.win32.*; final class OleEnumFORMATETC { - private COMObject iUnknown; private COMObject iEnumFORMATETC; private int refCount; @@ -37,15 +36,6 @@ int AddRef() { return refCount; } private void createCOMInterfaces() { - // register each of the interfaces that this object implements - iUnknown = new COMObject(new int[] {2, 0, 0}){ - @Override - public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} - @Override - public long /*int*/ method1(long /*int*/[] args) {return AddRef();} - @Override - public long /*int*/ method2(long /*int*/[] args) {return Release();} - }; iEnumFORMATETC = new COMObject(new int[] {2, 0, 0, 3, 1, 0, 1}){ @Override public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} @@ -63,11 +53,6 @@ private void createCOMInterfaces() { }; } private void disposeCOMInterfaces() { - - if (iUnknown != null) - iUnknown.dispose(); - iUnknown = null; - if (iEnumFORMATETC != null) iEnumFORMATETC.dispose(); iEnumFORMATETC = null; @@ -128,12 +113,7 @@ private int QueryInterface(long /*int*/ riid, long /*int*/ ppvObject) { GUID guid = new GUID(); COM.MoveMemory(guid, riid, GUID.sizeof); - if (COM.IsEqualGUID(guid, COM.IIDIUnknown)) { - OS.MoveMemory(ppvObject, new long /*int*/[] {iUnknown.getAddress()}, C.PTR_SIZEOF); - AddRef(); - return COM.S_OK; - } - if (COM.IsEqualGUID(guid, COM.IIDIEnumFORMATETC)) { + if (COM.IsEqualGUID(guid, COM.IIDIUnknown) || COM.IsEqualGUID(guid, COM.IIDIEnumFORMATETC)) { OS.MoveMemory(ppvObject, new long /*int*/[] {iEnumFORMATETC.getAddress()}, C.PTR_SIZEOF); AddRef(); return COM.S_OK; diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java index 7bb333cc59..abcf1bd234 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java @@ -50,7 +50,6 @@ import org.eclipse.swt.widgets.*; public class OleClientSite extends Composite { // Interfaces for this Ole Client Container - private COMObject iUnknown; COMObject iOleClientSite; private COMObject iAdviseSink; private COMObject iOleInPlaceSite; @@ -503,15 +502,6 @@ private int ContextSensitiveHelp(int fEnterMode) { } protected void createCOMInterfaces() { - iUnknown = new COMObject(new int[]{2, 0, 0}){ - @Override - public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} - @Override - public long /*int*/ method1(long /*int*/[] args) {return AddRef();} - @Override - public long /*int*/ method2(long /*int*/[] args) {return Release();} - }; - iOleClientSite = new COMObject(new int[]{2, 0, 0, 0, 3, 1, 0, 1, 0}){ @Override public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} @@ -620,12 +610,8 @@ private void deleteTempStorage() { tempStorage = null; } protected void disposeCOMInterfaces() { - if (iUnknown != null) - iUnknown.dispose(); - iUnknown = null; - if (iOleClientSite != null) - iOleClientSite.dispose(); + iOleClientSite.dispose(); iOleClientSite = null; if (iAdviseSink != null) @@ -1092,8 +1078,8 @@ protected int QueryInterface(long /*int*/ riid, long /*int*/ ppvObject) { GUID guid = new GUID(); COM.MoveMemory(guid, riid, GUID.sizeof); - if (COM.IsEqualGUID(guid, COM.IIDIUnknown)) { - OS.MoveMemory(ppvObject, new long /*int*/[] {iUnknown.getAddress()}, C.PTR_SIZEOF); + if (COM.IsEqualGUID(guid, COM.IIDIUnknown) || COM.IsEqualGUID(guid, COM.IIDIOleClientSite)) { + OS.MoveMemory(ppvObject, new long /*int*/[] {iOleClientSite.getAddress()}, C.PTR_SIZEOF); AddRef(); return COM.S_OK; } @@ -1102,11 +1088,6 @@ protected int QueryInterface(long /*int*/ riid, long /*int*/ ppvObject) { AddRef(); return COM.S_OK; } - if (COM.IsEqualGUID(guid, COM.IIDIOleClientSite)) { - OS.MoveMemory(ppvObject, new long /*int*/[] {iOleClientSite.getAddress()}, C.PTR_SIZEOF); - AddRef(); - return COM.S_OK; - } if (COM.IsEqualGUID(guid, COM.IIDIOleInPlaceSite)) { OS.MoveMemory(ppvObject, new long /*int*/[] {iOleInPlaceSite.getAddress()}, C.PTR_SIZEOF); AddRef(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java index 5fd0d11a77..9b094970df 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java @@ -322,16 +322,6 @@ private int ContextSensitiveHelp(int fEnterMode) { return COM.S_OK; } private void createCOMInterfaces() { - // Create each of the interfaces that this object implements - iUnknown = new COMObject(new int[]{2, 0, 0}){ - @Override - public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} - @Override - public long /*int*/ method1(long /*int*/[] args) {return AddRef();} - @Override - public long /*int*/ method2(long /*int*/[] args) {return Release();} - }; - iOleInPlaceFrame = new COMObject(new int[]{2, 0, 0, 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, 1, 2}){ @Override public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} @@ -364,11 +354,6 @@ private void createCOMInterfaces() { }; } private void disposeCOMInterfaces () { - - if (iUnknown != null) - iUnknown.dispose(); - iUnknown = null; - if (iOleInPlaceFrame != null) iOleInPlaceFrame.dispose(); iOleInPlaceFrame = null; diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OlePropertyChangeSink.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OlePropertyChangeSink.java index e866b2660d..672f56e5f1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OlePropertyChangeSink.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OlePropertyChangeSink.java @@ -24,7 +24,6 @@ final class OlePropertyChangeSink { private OleControlSite controlSite; //private IUnknown objIUnknown; - private COMObject iUnknown; private COMObject iPropertyNotifySink; private int refCount; @@ -66,16 +65,6 @@ void connect(IUnknown objIUnknown) { } } private void createCOMInterfaces() { - // register each of the interfaces that this object implements - iUnknown = new COMObject(new int[]{2, 0, 0}){ - @Override - public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} - @Override - public long /*int*/ method1(long /*int*/[] args) {return AddRef();} - @Override - public long /*int*/ method2(long /*int*/[] args) {return Release();} - }; - iPropertyNotifySink = new COMObject(new int[]{2, 0, 0, 1, 1}){ @Override public long /*int*/ method0(long /*int*/[] args) {return QueryInterface(args[0], args[1]);} @@ -108,8 +97,6 @@ void disconnect(IUnknown objIUnknown) { } } private void disposeCOMInterfaces() { - if (iUnknown != null) iUnknown.dispose(); - iUnknown = null; if (iPropertyNotifySink != null) iPropertyNotifySink.dispose(); iPropertyNotifySink = null; } @@ -157,12 +144,7 @@ private int QueryInterface(long /*int*/ riid, long /*int*/ ppvObject) { return COM.E_INVALIDARG; GUID guid = new GUID(); COM.MoveMemory(guid, riid, GUID.sizeof); - if (COM.IsEqualGUID(guid, COM.IIDIUnknown)) { - OS.MoveMemory(ppvObject, new long /*int*/[] {iUnknown.getAddress()}, C.PTR_SIZEOF); - AddRef(); - return COM.S_OK; - } - if (COM.IsEqualGUID(guid, COM.IIDIPropertyNotifySink)) { + if (COM.IsEqualGUID(guid, COM.IIDIUnknown) || COM.IsEqualGUID(guid, COM.IIDIPropertyNotifySink)) { OS.MoveMemory(ppvObject, new long /*int*/[] {iPropertyNotifySink.getAddress()}, C.PTR_SIZEOF); AddRef(); return COM.S_OK; -- cgit v1.2.3