1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Bug 568079: Reducing transitions from JAVA to native code (part 2)

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 <azoff@svenskalinuxforeningen.se>
Change-Id: I960954e332e05dfebcd0263f983bbbc6c64d46af
This commit is contained in:
Torbjörn Svensson 2020-11-05 21:32:19 +01:00 committed by Jonah Graham
parent d0c3b2aaff
commit 8b391a7f3a
2 changed files with 5 additions and 19 deletions

View file

@ -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)"

View file

@ -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<String> 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];