Skip to content

Commit

Permalink
feat(ants): pre-alloc slice correcty for with-defaults (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jun 16, 2024
1 parent 8b07060 commit 5c133fc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/ants/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewOptions(options ...Option) *Options {
return opts
}

// If enables options to be conditional. If ifo evaluates to true
// If enables options to be conditional. If condition evaluates to true
// then the option is returned, otherwise nil.
func If(condition bool, option Option) Option {
if condition {
Expand All @@ -34,15 +34,16 @@ func If(condition bool, option Option) Option {
}

func withDefaults(options ...Option) []Option {
const (
noDefaults = 1
)
o := make([]Option, 0, len(options)+noDefaults)
o = append(o,
defaults := []Option{
WithGenerator(&Sequential{
Format: "ID:%08d",
}),
WithSize(uint(runtime.NumCPU())),
}

o := make([]Option, 0, len(options)+len(defaults))
o = append(o,
defaults...,
)
o = append(o, options...)

Expand Down

0 comments on commit 5c133fc

Please sign in to comment.