From d0c3b2aaffba46b84b9cc2ef21f4ccd10ad6d714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Thu, 5 Nov 2020 21:32:19 +0100 Subject: [PATCH] Bug 568079: Reducing transitions from JAVA to native code (part 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Advapi32Util.registryGetValues() is more efficient to fetch all the values since the regiter only needs to be opened once. XXX: Due to a cycle in the dependencies we need to split this in two parts, this commit handles the core.native API change and the next commit handles the use of the new API Change-Id: Ifd9f1ccc44c652ef3b517278bd342a486155c5fb Signed-off-by: Torbjörn Svensson --- .../META-INF/MANIFEST.MF | 2 +- core/org.eclipse.cdt.core.native/pom.xml | 2 +- .../eclipse/cdt/utils/WindowsRegistry.java | 22 ++++++++++++++++- .../META-INF/MANIFEST.MF | 4 ++-- core/org.eclipse.cdt.core.win32/pom.xml | 2 +- .../core/win32/WindowsRegistryImpl.java | 24 +++++++++++++++++++ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF index 07649b97f34..14341ae6e72 100644 --- a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core.native;singleton:=true -Bundle-Version: 6.0.100.qualifier +Bundle-Version: 6.1.0.qualifier Bundle-Activator: org.eclipse.cdt.internal.core.natives.CNativePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core.native/pom.xml b/core/org.eclipse.cdt.core.native/pom.xml index 0bee5d6e28a..93d4098d2cd 100644 --- a/core/org.eclipse.cdt.core.native/pom.xml +++ b/core/org.eclipse.cdt.core.native/pom.xml @@ -23,7 +23,7 @@ ../../pom.xml - 6.0.100-SNAPSHOT + 6.1.0-SNAPSHOT org.eclipse.cdt.core.native eclipse-plugin diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java index f2054512232..c35b672efb1 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/WindowsRegistry.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.cdt.utils; +import java.util.Map; + import org.eclipse.cdt.internal.core.natives.CNativePlugin; import org.eclipse.core.runtime.CoreException; @@ -51,6 +53,15 @@ public abstract class WindowsRegistry { */ public abstract String getLocalMachineValue(String subkey, String name); + /** + * Given a subkey of HKEY_LOCAL_MACHINE, return the map of valueName => value. + * The return value is an empty map on error or when the subkey does not exist. + * @param subkey subkey of HKEY_LOCAL_MACHINE + * @return valueName => value map of the entries in subkey + * @since 6.1 + */ + public abstract Map getLocalMachineValues(String subkey); + /** * Given a subkey of HKEY_LOCAL_MACHINE, and an index (starting from 0) * to the key's array of values, return the name of the indexed value. @@ -69,7 +80,7 @@ public abstract class WindowsRegistry { * The return value is null on any error or when the index is invalid. * The key name can be used in the above getLocalMachineValueName() * to retrieve value names. - * @param subkey subkey of HKEY_CURRENT_USER + * @param subkey subkey of HKEY_LOCAL_MACHINE * @param index index to the subkey's array of values, starting from 0. * @return name of registry value or null if not found */ @@ -85,6 +96,15 @@ public abstract class WindowsRegistry { */ public abstract String getCurrentUserValue(String subkey, String name); + /** + * Given a subkey of HKEY_CURRENT_USER, return the map of valueName => value. + * The return value is an empty map on error or when the subkey does not exist. + * @param subkey subkey of HKEY_CURRENT_USER + * @return valueName => value map of the entries in subkey + * @since 6.1 + */ + public abstract Map getCurrentUserValues(String subkey); + /** * Given a subkey of HKEY_CURRENT_USER, and an index (starting from 0) * to the key's array of values, return the name of the indexed value. diff --git a/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF index 17c5c1cdc83..7abccf9023e 100644 --- a/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.win32/META-INF/MANIFEST.MF @@ -2,9 +2,9 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %fragmentName.win32 Bundle-SymbolicName: org.eclipse.cdt.core.win32; singleton:=true -Bundle-Version: 6.0.0.qualifier +Bundle-Version: 6.0.100.qualifier Bundle-Vendor: %providerName -Fragment-Host: org.eclipse.cdt.core.native;bundle-version="[6.0.0,7.0.0)" +Fragment-Host: org.eclipse.cdt.core.native;bundle-version="[6.1.0,7.0.0)" Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-11 Eclipse-PlatformFilter: (osgi.os=win32) diff --git a/core/org.eclipse.cdt.core.win32/pom.xml b/core/org.eclipse.cdt.core.win32/pom.xml index 3c635742105..4de5713f946 100644 --- a/core/org.eclipse.cdt.core.win32/pom.xml +++ b/core/org.eclipse.cdt.core.win32/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 6.0.0-SNAPSHOT + 6.0.100-SNAPSHOT org.eclipse.cdt.core.win32 eclipse-plugin diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java index 0327dbffcf9..42b0431c76a 100644 --- a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java +++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.win32; +import java.util.Collections; +import java.util.Map; + import org.eclipse.cdt.internal.core.natives.CNativePlugin; import org.eclipse.cdt.utils.WindowsRegistry; import org.eclipse.core.runtime.Platform; @@ -41,6 +44,11 @@ public class WindowsRegistryImpl extends WindowsRegistry { return getValue(WinReg.HKEY_LOCAL_MACHINE, subkey, name); } + @Override + public Map getLocalMachineValues(String subkey) { + return getValues(WinReg.HKEY_LOCAL_MACHINE, subkey); + } + @Override public String getLocalMachineValueName(String subkey, int index) { return getValueName(WinReg.HKEY_LOCAL_MACHINE, subkey, index); @@ -56,6 +64,11 @@ public class WindowsRegistryImpl extends WindowsRegistry { return getValue(WinReg.HKEY_CURRENT_USER, subkey, name); } + @Override + public Map getCurrentUserValues(String subkey) { + return getValues(WinReg.HKEY_CURRENT_USER, subkey); + } + @Override public String getCurrentUserValueName(String subkey, int index) { return getValueName(WinReg.HKEY_CURRENT_USER, subkey, index); @@ -118,4 +131,15 @@ public class WindowsRegistryImpl extends WindowsRegistry { return null; } } + + private Map getValues(HKEY key, String subkey) { + try { + return Advapi32Util.registryGetValues(key, subkey); + } catch (Win32Exception e) { + if (DEBUG) { + CNativePlugin.log(String.format("Unable to get values for %s", subkey), e); //$NON-NLS-1$ + } + return Collections.emptyMap(); + } + } }