Skip to content

Commit

Permalink
Why loop with O(2n) when you can basically O(1)?
Browse files Browse the repository at this point in the history
  • Loading branch information
rpearce committed Sep 19, 2022
1 parent ab3f9e0 commit 26363dc
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,12 @@ func root(args []string) error {
return nil
}

cmds := []Runner{}

for code := range statuses {
cmds = append(cmds, NewStatusCommand(code))
}

subcommand := os.Args[1]

for _, cmd := range cmds {
if cmd.Name() == subcommand {
cmd.Init(os.Args[2:])
return cmd.Run()
}
if status, exists := statuses[subcommand]; exists {
cmd := NewStatusCommand(status.code)
cmd.Init(os.Args[2:])
return cmd.Run()
}

return fmt.Errorf("httpwut: '%s' might not be an HTTP status code", subcommand)
Expand Down

0 comments on commit 26363dc

Please sign in to comment.