Skip to content

Commit

Permalink
Create outlet formatter once rather than for each line
Browse files Browse the repository at this point in the history
The output padding is based upon the longest name of processes and thus never
changes at runtime so we can optimize things a bit by only creating the output
formatter pattern once at startup.
  • Loading branch information
sehrope committed Apr 12, 2020
1 parent cea46c3 commit 483193b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions outlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type OutletFactory struct {
Padding int
LeftFormatter string

sync.Mutex
}
Expand Down Expand Up @@ -80,8 +80,7 @@ func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, i
if colorize {
ct.ChangeColor(leftC, true, ct.None, false)
}
formatter := fmt.Sprintf("%%-%ds | ", of.Padding)
fmt.Printf(formatter, left)
fmt.Printf(of.LeftFormatter, left)

if colorize {
if isError {
Expand Down
2 changes: 1 addition & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func runStart(cmd *Command, args []string) {
handleError(err)

of := NewOutletFactory()
of.Padding = pf.LongestProcessName(concurrency)
of.LeftFormatter = fmt.Sprintf("%%-%ds | ", pf.LongestProcessName(concurrency))

f := &Forego{
outletFactory: of,
Expand Down

0 comments on commit 483193b

Please sign in to comment.