Skip to content

Commit

Permalink
Run parsers in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Oct 25, 2024
1 parent 461ef7a commit 664207f
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"sort"
"strings"
"sync"
"text/template"

"github.com/nokia/ntt/internal/env"
Expand Down Expand Up @@ -77,36 +78,48 @@ func printJSON(report *ConfigReport, keys []string) error {
}

if !dumb {
var list []project.TestConfig
mu := sync.Mutex{}
wg := sync.WaitGroup{}
wg.Add(len(files))
glist := make([]project.TestConfig, 0, len(files))
for _, file := range files {
tree := ttcn3.ParseFile(file)
if tree.Err != nil {
report.err = errors.Join(report.err, tree.Err)
}
tree.Inspect(func(n syntax.Node) bool {
switch n := n.(type) {
case *syntax.FuncDecl:
if n.IsTest() || n.IsControl() {
go func() {
defer wg.Done()

tree := ttcn3.ParseFile(file)
if tree.Err != nil {
report.err = errors.Join(report.err, tree.Err)
}
list := make([]project.TestConfig, 0, len(tree.Names))
tree.Inspect(func(n syntax.Node) bool {
switch n := n.(type) {
case *syntax.FuncDecl:
if n.IsTest() || n.IsControl() {
break
}
return false
case *syntax.ControlPart:
break
default:
return true
}
name := tree.QualifiedName(n)
tc, err := report.TestConfigs(name, presets...)
if err != nil {
log.Debugf("implementation error: %s\n", err)
}
if len(tc) > 0 {
list = append(list, tc...)
}
return false
case *syntax.ControlPart:
break
default:
return true
}
name := tree.QualifiedName(n)
tc, err := report.TestConfigs(name, presets...)
if err != nil {
log.Debugf("implementation error: %s\n", err)
}
if len(tc) > 0 {
list = append(list, tc...)
}
return false
})
})
mu.Lock()
glist = append(glist, list...)
mu.Unlock()
}()
}
report.Execute = list
wg.Wait()
report.Execute = glist
}

b, err := yaml.MarshalJSON(report)
Expand Down

0 comments on commit 664207f

Please sign in to comment.