Precompile port-filter regexp
This commit is contained in:
@@ -6,10 +6,15 @@
|
||||
|
||||
package serial
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const devFolder = "/dev"
|
||||
const regexFilter = "^(cu|tty)\\..*"
|
||||
|
||||
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||
|
||||
const ioctlTcgetattr = unix.TIOCGETA
|
||||
const ioctlTcsetattr = unix.TIOCSETA
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
|
||||
package serial
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const devFolder = "/dev"
|
||||
const regexFilter = "^(cu|tty)\\..*"
|
||||
|
||||
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||
|
||||
// termios manipulation functions
|
||||
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
|
||||
package serial
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const devFolder = "/dev"
|
||||
const regexFilter = "(ttyS|ttyHS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO|ttymxc)[0-9]{1,3}"
|
||||
|
||||
var osPortFilter = regexp.MustCompile("(ttyS|ttyHS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO|ttymxc)[0-9]{1,3}")
|
||||
|
||||
// termios manipulation functions
|
||||
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
|
||||
package serial
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const devFolder = "/dev"
|
||||
const regexFilter = "^(cu|tty)\\..*"
|
||||
|
||||
var osPortFiler = regexp.MustCompile("^(cu|tty)\\..*")
|
||||
|
||||
// termios manipulation functions
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user