Optimization

This commit is contained in:
Alex Yatskov 2015-11-03 10:13:04 +09:00
parent b5470ba396
commit 38632b1e4a

View File

@ -50,18 +50,21 @@ func New(srcDir, dstDir string) Goldsmith {
refs: make(map[string]bool),
}
gs.scan()
gs.scanFs()
return gs
}
func (gs *goldsmith) scan() {
func (gs *goldsmith) scanFs() {
fileMatches, _, err := scanDir(gs.srcDir)
if err != nil {
gs.err = err
return
}
s := stage{nil, make(chan *File, len(fileMatches))}
s := gs.makeStage()
gs.stages = append(gs.stages, s)
go func() {
defer close(s.output)
for _, match := range fileMatches {
@ -80,11 +83,10 @@ func (gs *goldsmith) scan() {
s.output <- file
}
gs.stages = append(gs.stages, s)
}()
}
func (gs *goldsmith) clean() {
func (gs *goldsmith) cleanupFiles() {
fileMatches, _, err := scanDir(gs.dstDir)
if err != nil {
gs.err = err
@ -107,7 +109,7 @@ func (gs *goldsmith) clean() {
}
}
func (gs *goldsmith) export(file *File) {
func (gs *goldsmith) exportFile(file *File) {
defer func() {
file.Buff = nil
}()
@ -132,9 +134,9 @@ func (gs *goldsmith) export(file *File) {
}
func (gs *goldsmith) makeStage() stage {
s := stage{
gs.stages[len(gs.stages)-1].output,
make(chan *File),
s := stage{output: make(chan *File)}
if len(gs.stages) > 0 {
s.input = gs.stages[len(gs.stages)-1].output
}
gs.stages = append(gs.stages, s)
@ -228,11 +230,11 @@ func (gs *goldsmith) Complete() ([]*File, error) {
var files []*File
for file := range s.output {
gs.export(file)
gs.exportFile(file)
files = append(files, file)
}
gs.clean()
gs.cleanupFiles()
return files, gs.err
}