Skip to content

Commit

Permalink
Issue #226: Use strings.HasPrefix instead of regexp.MatchString
Browse files Browse the repository at this point in the history
This fixes:
pkg/crc/preflight/preflight_checks_linux.go:277:35: SA6000: calling regexp.MatchString in a loop has poor performance, consider using regexp.Compile (staticcheck)
		match, err := regexp.MatchString("^crc\\s", stdOut)
		                                ^
pkg/crc/preflight/preflight_checks_linux.go:346:35: SA6000: calling regexp.MatchString in a loop has poor performance, consider using regexp.Compile (staticcheck)
		match, err := regexp.MatchString("^crc\\s", stdOut)
		                                ^

#226
  • Loading branch information
cfergeau authored and praveenkumar committed Aug 27, 2019
1 parent d3b2e15 commit 30892f6
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/crc/preflight/preflight_checks_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ func checkLibvirtCrcNetworkAvailable() (bool, error) {
outputSlice := strings.Split(stdOut, "\n")
for _, stdOut = range outputSlice {
stdOut = strings.TrimSpace(stdOut)
match, err := regexp.MatchString("^crc\\s", stdOut)
if err != nil {
return false, err
}
if match {
if strings.HasPrefix(stdOut, "crc") {
logging.Debug("libvirt 'crc' network exists")
logging.Debug("Checking if libvirt 'crc' network definition contains ", constants.DefaultHostname)
// Check if the network have defined hostname. It might be possible that User already have an outdated crc network
Expand Down Expand Up @@ -352,11 +348,7 @@ func checkLibvirtCrcNetworkActive() (bool, error) {

for _, stdOut = range outputSlice {
stdOut = strings.TrimSpace(stdOut)
match, err := regexp.MatchString("^crc\\s", stdOut)
if err != nil {
return false, err
}
if match && strings.Contains(stdOut, "active") {
if strings.HasPrefix(stdOut, "crc") && strings.Contains(stdOut, "active") {
logging.Debug("libvirt 'crc' network is already active")
return true, nil
}
Expand Down

0 comments on commit 30892f6

Please sign in to comment.