Optimization

This commit is contained in:
Alex Yatskov 2015-11-01 22:25:26 +09:00
parent 2a32c99767
commit a6b0c84934
2 changed files with 19 additions and 23 deletions

View File

@ -96,19 +96,10 @@ func (gs *goldsmith) chainSingle(s stage, cs ChainerSingle, globs []string) {
wg.Add(1) wg.Add(1)
go func(f File) { go func(f File) {
defer wg.Done() defer wg.Done()
if skipFile(&f, globs) {
matched := true
if len(globs) > 0 {
var err error
if matched, err = globMatch(globs, file.Path); err != nil {
file.Err = err
}
}
if f.Err == nil && matched {
s.output <- cs.ChainSingle(f)
} else {
s.output <- f s.output <- f
} else {
s.output <- cs.ChainSingle(f)
} }
}(file) }(file)
} }
@ -123,18 +114,10 @@ func (gs *goldsmith) chainMultiple(s stage, cm ChainerMultiple, globs []string)
go cm.ChainMultiple(filtered, s.output) go cm.ChainMultiple(filtered, s.output)
for file := range s.input { for file := range s.input {
matched := true if skipFile(&file, globs) {
if len(globs) > 0 {
var err error
if matched, err = globMatch(globs, file.Path); err != nil {
file.Err = err
}
}
if file.Err == nil && matched {
filtered <- file
} else {
s.output <- file s.output <- file
} else {
filtered <- file
} }
} }
} }

13
util.go
View File

@ -39,3 +39,16 @@ func globMatch(globs []string, name string) (bool, error) {
return match, err return match, err
} }
func skipFile(file *File, globs []string) bool {
if file.Err != nil {
return true
}
matched := true
if len(globs) > 0 {
matched, file.Err = globMatch(globs, file.Path)
}
return !matched
}