Move regex compile outside loop
This commit is contained in:
@@ -220,6 +220,10 @@ func nativeGetPortsList() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ports := make([]string, 0, len(files))
|
ports := make([]string, 0, len(files))
|
||||||
|
regex, err := regexp.Compile(regexFilter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
// Skip folders
|
// Skip folders
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
@@ -227,11 +231,7 @@ func nativeGetPortsList() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keep only devices with the correct name
|
// Keep only devices with the correct name
|
||||||
match, err := regexp.MatchString(regexFilter, f.Name())
|
if !regex.MatchString(f.Name()) {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if !match {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user