From a2d78071c1d80eb3c488a24e974c2892d7a60663 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 5 Mar 2025 11:29:56 +0100 Subject: [PATCH] cmd/docker: small performance optimizations for running hooks Order conditions to check for lightweight ones first; - checck if the command is not nil - dockerCli.Out().IsTerminal() is a lightweight getter - dockerCli.HooksEnabled() checks for env-vars, parses booleans, and reading the CLI config-file Signed-off-by: Sebastiaan van Stijn --- cmd/docker/docker.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 5183d455f9..05d1a59481 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -446,7 +446,7 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { if err != nil || pluginmanager.IsPluginCommand(ccmd) { err := tryPluginRun(ctx, dockerCli, cmd, args[0], envs) if err == nil { - if dockerCli.HooksEnabled() && dockerCli.Out().IsTerminal() && ccmd != nil { + if ccmd != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() { pluginmanager.RunPluginHooks(ctx, dockerCli, cmd, ccmd, args) } return nil @@ -471,7 +471,7 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { // If the command is being executed in an interactive terminal // and hook are enabled, run the plugin hooks. - if dockerCli.HooksEnabled() && dockerCli.Out().IsTerminal() && subCommand != nil { + if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() { var errMessage string if err != nil { errMessage = err.Error()