Skip to content

Commit

Permalink
internal/graphicscommand: add a debug.IsDebug check before splitting …
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
gabstv authored Oct 18, 2024
1 parent 0ec2c4b commit 2ad0e9a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/graphicscommand/commandqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ad0e9a

Please sign in to comment.