Precompile port-filter regexp

This commit is contained in:
Cristian Maglie
2024-02-20 15:24:08 +01:00
parent bcd8695df4
commit 14e5ea68ce
5 changed files with 29 additions and 14 deletions

View File

@@ -11,7 +11,6 @@ package serial
import (
"fmt"
"os"
"regexp"
"strings"
"sync"
"sync/atomic"
@@ -298,10 +297,6 @@ func nativeGetPortsList() ([]string, error) {
}
ports := make([]string, 0, len(files))
regex, err := regexp.Compile(regexFilter)
if err != nil {
return nil, err
}
for _, f := range files {
// Skip folders
if f.IsDir() {
@@ -309,7 +304,7 @@ func nativeGetPortsList() ([]string, error) {
}
// Keep only devices with the correct name
if !regex.MatchString(f.Name()) {
if !osPortFilter.MatchString(f.Name()) {
continue
}