Skip to content

Commit

Permalink
Add suggestion for regex compilation to iflist.go file
Browse files Browse the repository at this point in the history
This will move regex out of the loop
  • Loading branch information
elivlo committed May 10, 2022
1 parent e6f7814 commit 98c1363
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions iflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ func parseInterfaces(content []byte) *InterfaceList {
output := string(content)
lines := strings.Split(output, "\n")

interfaceRegex := regexp.MustCompile(`\*INTERFACES\*`)
routesRegex := regexp.MustCompile(`\*ROUTES\*`)
for i, line := range lines {
if match, _ := regexp.MatchString(`[\*]INTERFACES[\*]`, line); match {
if interfaceRegex.MatchString(line) {
for _, l := range lines[i+2:] {
if iface := convertInterface(l); iface != nil {
list.Interfaces = append(list.Interfaces, iface)
}
}
}

if match, _ := regexp.MatchString(`[\*]ROUTES[\*]`, line); match {
if routesRegex.MatchString(line) {
for _, l := range lines[i+2:] {
if route := convertRoute(l); route != nil {
list.Routes = append(list.Routes, route)
Expand Down

0 comments on commit 98c1363

Please sign in to comment.