Merge pull request #110 from cmaglie/slight_performance_fix

Move regex compile outside loop
This commit is contained in:
Cristian Maglie
2022-02-18 12:40:50 +01:00
committed by GitHub

View File

@@ -265,6 +265,10 @@ 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() {
@@ -272,11 +276,7 @@ func nativeGetPortsList() ([]string, error) {
}
// Keep only devices with the correct name
match, err := regexp.MatchString(regexFilter, f.Name())
if err != nil {
return nil, err
}
if !match {
if !regex.MatchString(f.Name()) {
continue
}