From 2ad0e9a9dbe53b3bd0672110d59aa75e627b1ce3 Mon Sep 17 00:00:00 2001 From: Gabriel Ochsenhofer Date: Fri, 18 Oct 2024 10:46:28 -0300 Subject: [PATCH] internal/graphicscommand: add a debug.IsDebug check before splitting strings (#3134) Since `debug.IsDebug` is a constant, by putting the `strings.Cut` calls inside the check this makes the `(*commandqueue).flush` method faster when Ebitengine is compiled without the debug build tag. Without the if `debug.IsDebug` check, unnecessary allocations occur (since the logger is a noop logger when debug is disabled). --- internal/graphicscommand/commandqueue.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/graphicscommand/commandqueue.go b/internal/graphicscommand/commandqueue.go index a7714fb0d..388a18563 100644 --- a/internal/graphicscommand/commandqueue.go +++ b/internal/graphicscommand/commandqueue.go @@ -305,14 +305,16 @@ func (q *commandQueue) flush(graphicsDriver graphicsdriver.Graphics, endFrame bo if err := c.Exec(q, graphicsDriver, indexOffset); err != nil { return err } - str := c.String() - for { - head, tail, ok := strings.Cut(str, "\n") - logger.FrameLogf(" %s\n", head) - if !ok { - break + if debug.IsDebug { + str := c.String() + for { + head, tail, ok := strings.Cut(str, "\n") + logger.FrameLogf(" %s\n", head) + if !ok { + break + } + str = tail } - str = tail } // TODO: indexOffset should be reset if the command type is different // from the previous one. This fix is needed when another drawing command is