]> Cypherpunks.ru repositories - goredo.git/blobdiff - path.go
Storage optimisations for the same often used data
[goredo.git] / path.go
diff --git a/path.go b/path.go
index 0c961960e8c5186e9fba22091fe8c84f432bcad1..e7f3359b09854c0010651995ddf875bb62321ac3 100644 (file)
--- a/path.go
+++ b/path.go
@@ -5,6 +5,8 @@ import (
        "path/filepath"
 )
 
+var TgtCache = make(map[string]*Tgt)
+
 func mustAbs(pth string) string {
        pth, err := filepath.Abs(pth)
        if err != nil {
@@ -40,12 +42,21 @@ type Tgt struct {
 }
 
 func NewTgt(tgt string) *Tgt {
-       t := Tgt{a: mustAbs(tgt)}
+       a := mustAbs(tgt)
+       if TgtCache != nil {
+               if t := TgtCache[a]; t != nil {
+                       return t
+               }
+       }
+       t := Tgt{a: a}
        t.h, t.t = path.Split(t.a)
        if len(t.h) > 1 {
                t.h = t.h[:len(t.h)-1]
        }
        t.rel = mustRel(Cwd, t.a)
+       if TgtCache != nil {
+               TgtCache[a] = &t
+       }
        return &t
 }