Przeglądaj źródła

build: Trivial perf improvement of shouldRebuildAssets

Jakob Borg 9 lat temu
rodzic
commit
b49df09fec
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5 3
      build.go

+ 5 - 3
build.go

@@ -13,6 +13,7 @@ import (
 	"archive/zip"
 	"archive/zip"
 	"bytes"
 	"bytes"
 	"compress/gzip"
 	"compress/gzip"
+	"errors"
 	"flag"
 	"flag"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
@@ -572,14 +573,15 @@ func shouldRebuildAssets(target, srcdir string) bool {
 	// so we should rebuild it.
 	// so we should rebuild it.
 	currentBuild := info.ModTime()
 	currentBuild := info.ModTime()
 	assetsAreNewer := false
 	assetsAreNewer := false
+	stop := errors.New("no need to iterate further")
 	filepath.Walk(srcdir, func(path string, info os.FileInfo, err error) error {
 	filepath.Walk(srcdir, func(path string, info os.FileInfo, err error) error {
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
-		if assetsAreNewer {
-			return nil
+		if info.ModTime().After(currentBuild) {
+			assetsAreNewer = true
+			return stop
 		}
 		}
-		assetsAreNewer = info.ModTime().After(currentBuild)
 		return nil
 		return nil
 	})
 	})