]> Cypherpunks.ru repositories - goredo.git/blobdiff - targets.go
Refactor target paths, less CPU, less memory, more clarity
[goredo.git] / targets.go
index 6459a2db5529d9061ce393b044073f62e9c2ba71..662612ea976b77f8418abc1d3c1fb4cb51ae541b 100644 (file)
@@ -25,7 +25,6 @@ import (
 )
 
 func targetsCollect(root string, tgts map[string]struct{}) error {
-       root = mustAbs(root)
        dir, err := os.Open(root)
        if err != nil {
                return ErrLine(err)
@@ -72,9 +71,9 @@ func targetsCollect(root string, tgts map[string]struct{}) error {
 }
 
 func targetsWalker(tgts []string) ([]string, error) {
-       tgtsMap := map[string]struct{}{}
+       tgtsMap := make(map[string]struct{})
        for _, tgt := range tgts {
-               if err := targetsCollect(tgt, tgtsMap); err != nil {
+               if err := targetsCollect(mustAbs(tgt), tgtsMap); err != nil {
                        return nil, err
                }
        }
@@ -86,12 +85,15 @@ func targetsWalker(tgts []string) ([]string, error) {
 }
 
 func collectWholeDeps(
-       tgts map[string]struct{},
-       deps map[string]map[string]struct{},
-       seen map[string]struct{},
+       tgts map[string]*Tgt,
+       deps map[string]map[string]*Tgt,
+       seen map[string]*Tgt,
 ) {
-       for tgt := range tgts {
-               seen[tgt] = struct{}{}
-               collectWholeDeps(deps[tgt], deps, seen)
+       for _, tgt := range tgts {
+               if _, exists := seen[tgt.a]; exists {
+                       continue
+               }
+               seen[tgt.a] = tgt
+               collectWholeDeps(deps[tgt.a], deps, seen)
        }
 }