Skip to content

Commit

Permalink
expand: allocate fewer objects in Fields
Browse files Browse the repository at this point in the history
          │     old     │             new              │
          │   sec/op    │   sec/op     vs base         │
    Run-8   1.494m ± 6%   1.487m ± 2%  ~ (p=0.645 n=8)

          │     old      │                new                 │
          │     B/op     │     B/op      vs base              │
    Run-8   71.03Ki ± 0%   70.83Ki ± 0%  -0.28% (p=0.016 n=8)

          │    old     │               new                │
          │ allocs/op  │ allocs/op   vs base              │
    Run-8   856.0 ± 0%   826.0 ± 0%  -3.50% (p=0.000 n=8)
  • Loading branch information
mvdan committed May 26, 2024
1 parent bbbe48a commit 793d364
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,17 @@ func Fields(cfg *Config, words ...*syntax.Word) ([]string, error) {
for _, field := range wfields {
path, doGlob := cfg.escapedGlobField(field)
var matches []string
var syntaxError *pattern.SyntaxError
if doGlob && cfg.ReadDir2 != nil {
matches, err = cfg.glob(dir, path)
if !errors.As(err, &syntaxError) {
if err != nil {
if err != nil {
// We avoid [errors.As] as it allocates,
// and we know that [Config.glob] returns [pattern.Regexp] errors without wrapping.
if _, ok := err.(*pattern.SyntaxError); !ok {
return nil, err
}
if len(matches) > 0 || cfg.NullGlob {
fields = append(fields, matches...)
continue
}
} else if len(matches) > 0 || cfg.NullGlob {
fields = append(fields, matches...)
continue
}
}
fields = append(fields, cfg.fieldJoin(field))
Expand Down

0 comments on commit 793d364

Please sign in to comment.