From 8b391a7f3a914568bf6cc122d61088992763d377 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 2) 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 previous commit handles the core.native API change and this commit handles the use of the new API Signed-off-by: Torbjörn Svensson Change-Id: I960954e332e05dfebcd0263f983bbbc6c64d46af --- .../META-INF/MANIFEST.MF | 2 +- .../org/eclipse/cdt/serial/SerialPort.java | 22 ++++--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF index 52b48f6b3df..1614f278e13 100644 --- a/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF +++ b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF @@ -8,4 +8,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.cdt.serial Automatic-Module-Name: org.eclipse.cdt.native.serial Bundle-Localization: plugin -Require-Bundle: org.eclipse.cdt.core.native;bundle-version="6.0.100" +Require-Bundle: org.eclipse.cdt.core.native;bundle-version="[6.1.0,7.0.0)" diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java index 80970dafe25..a305eb30cd1 100644 --- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java +++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java @@ -19,11 +19,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -258,22 +256,10 @@ public class SerialPort { } else if (osName.startsWith("Windows")) { //$NON-NLS-1$ final WindowsRegistry registry = WindowsRegistry.getRegistry(); if (registry != null) { - final String subKey = "HARDWARE\\DEVICEMAP\\SERIALCOMM"; //$NON-NLS-1$ - - List ports = new ArrayList<>(); - int i = 0; - String valueName = null; - String value = null; - do { - valueName = registry.getLocalMachineValueName(subKey, i++); - if (valueName != null) { - value = registry.getLocalMachineValue(subKey, valueName); - if (value != null) { - ports.add(value); - } - } - } while (valueName != null && value != null); - return ports.toArray(new String[ports.size()]); + return registry.getLocalMachineValues("HARDWARE\\DEVICEMAP\\SERIALCOMM").values().stream() //$NON-NLS-1$ + .filter(String.class::isInstance) // Should only be strings here, but lets be safe + .map(String.class::cast) // + .toArray(String[]::new); } } return new String[0];