]> Cypherpunks.ru repositories - goredo.git/commitdiff
Cache already parsed .rec during collectDeps
authorSergey Matveev <stargrave@stargrave.org>
Fri, 29 Sep 2023 16:18:03 +0000 (19:18 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Sep 2023 09:40:23 +0000 (12:40 +0300)
ifchange.go
main.go
usage.go

index b3df3a8a34881bdffc45ff58f3e545358b6789cc..8a4677597aa2473f0716699565ef52e7dd6458ed 100644 (file)
@@ -28,8 +28,13 @@ func collectDeps(
        level int,
        deps map[string]map[string]struct{},
        includeSrc bool,
+       seen map[string]struct{},
 ) []string {
        cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
+       tgtFull := path.Join(cwd, tgt)
+       if _, ok := seen[tgtFull]; ok {
+               return nil
+       }
        depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
        fdDep, err := os.Open(depPath)
        if err != nil {
@@ -40,6 +45,7 @@ func collectDeps(
        if err != nil {
                return nil
        }
+       seen[tgtFull] = struct{}{}
        var alwayses []string
        returnReady := false
        tgtRel := cwdMustRel(cwd, tgt)
@@ -76,10 +82,8 @@ func collectDeps(
                                m[tgtRel] = struct{}{}
                                deps[depRel] = m
                        }
-                       alwayses = append(
-                               alwayses,
-                               collectDeps(cwd, dep, level+1, deps, includeSrc)...,
-                       )
+                       alwayses = append(alwayses,
+                               collectDeps(cwd, dep, level+1, deps, includeSrc, seen)...)
                }
        }
        return alwayses
@@ -90,8 +94,9 @@ func buildDependants(tgts []string) map[string]struct{} {
        tracef(CDebug, "collecting deps")
        seen := map[string]struct{}{}
        deps := map[string]map[string]struct{}{}
+       collectDepsSeen := make(map[string]struct{})
        for _, tgtInitial := range tgts {
-               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false) {
+               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false, collectDepsSeen) {
                        if tgt != tgtInitial {
                                seen[tgt] = struct{}{}
                        }
@@ -100,6 +105,7 @@ func buildDependants(tgts []string) map[string]struct{} {
        if len(seen) == 0 {
                return seen
        }
+       collectDepsSeen = nil
 
        levelOrig := Level
        defer func() {
diff --git a/main.go b/main.go
index 8c95d84bd3ed76135ce08086ebb595498b8635e0..0fb48d6819911eed9647a20611bf9c50580c61a1 100644 (file)
--- a/main.go
+++ b/main.go
@@ -455,7 +455,7 @@ CmdSwitch:
                }
                deps := map[string]map[string]struct{}{}
                for _, tgt := range tgtsKnown {
-                       collectDeps(Cwd, tgt, 0, deps, true)
+                       collectDeps(Cwd, tgt, 0, deps, true, map[string]struct{}{})
                }
                seen := map[string]struct{}{}
                for _, tgt := range tgts {
index 6f6a5ccb8e8c737453d118a39e656ef456d9ba92..4cffd4a9c6d89c4894f9d93ea2059c4632f676a2 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -24,7 +24,7 @@ import (
 )
 
 const (
-       Version  = "1.32.0"
+       Version  = "1.33.0"
        Warranty = `Copyright (C) 2020-2023 Sergey Matveev
 
 This program is free software: you can redistribute it and/or modify