[serial] Use a fast path to avoid pattern matching (#4255)

Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
This commit is contained in:
joerg1985 2024-05-28 23:53:02 +02:00 committed by GitHub
parent a5a7eee9a8
commit 9068ab2fac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -222,7 +222,10 @@ public class SysfsUsbSerialScanner implements UsbSerialScanner {
* of a USB device.
*/
private @Nullable Path getUsbInterfaceParentPath(Path sysfsPath) {
if (sysfsPath.getFileName() == null) {
if (sysfsPath.toString().indexOf('-') == -1) {
// a fast path to avoid pattern matching for dozens of not matching directories
return null;
} else if (sysfsPath.getFileName() == null) {
return null;
} else if (SYSFS_USB_INTERFACE_DIRECTORY_PATTERN.matcher(sysfsPath.getFileName().toString()).matches()) {
return sysfsPath;