From c9a3ef28eb62f90b21288e6545e1cf128d5f9cea Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 7 Apr 2024 22:27:26 +0900 Subject: [PATCH] text/v2: avoid creating an option struct when the given option is nil --- text/v2/layout.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/text/v2/layout.go b/text/v2/layout.go index efe1d0b5d..fe874e01a 100644 --- a/text/v2/layout.go +++ b/text/v2/layout.go @@ -101,15 +101,17 @@ type LayoutOptions struct { // If the vertical alignment is center, the rendering region's middle Y comes to the origin. // If the vertical alignment is bottom, the rendering region's bottom Y comes to the origin. func Draw(dst *ebiten.Image, text string, face Face, options *DrawOptions) { - if options == nil { - options = &DrawOptions{} + var layoutOp LayoutOptions + var drawOp ebiten.DrawImageOptions + + if options != nil { + layoutOp = options.LayoutOptions + drawOp = options.DrawImageOptions } - // Copy the options to avoid modifying the original options (#2954). - drawOp := options.DrawImageOptions geoM := drawOp.GeoM - for _, g := range AppendGlyphs(nil, text, face, &options.LayoutOptions) { + for _, g := range AppendGlyphs(nil, text, face, &layoutOp) { if g.Image == nil { continue }