From d5c6fd174f6834166137a7a8611bf6c451ea6f56 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 25 Oct 2024 13:58:16 +0900 Subject: [PATCH] text/v2: remove faceWithCache's mutex faceWithCache is not exported, and the functions using faceWithCache are not concurrent safe. Thus, it doesn't make sense to protect faceWithCache by mutex. Rather, this affects performance. --- text/v2/goxcache.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/text/v2/goxcache.go b/text/v2/goxcache.go index b871b78c0..bcc4f6d10 100644 --- a/text/v2/goxcache.go +++ b/text/v2/goxcache.go @@ -16,7 +16,6 @@ package text import ( "image" - "sync" "golang.org/x/image/font" "golang.org/x/image/math/fixed" @@ -44,8 +43,6 @@ type faceWithCache struct { glyphBoundsCache map[rune]glyphBoundsCacheValue glyphAdvanceCache map[rune]glyphAdvanceCacheValue kernCache map[kernCacheKey]fixed.Int26_6 - - m sync.Mutex } func (f *faceWithCache) Close() error { @@ -53,9 +50,6 @@ func (f *faceWithCache) Close() error { return err } - f.m.Lock() - defer f.m.Unlock() - f.glyphBoundsCache = nil f.glyphAdvanceCache = nil f.kernCache = nil @@ -67,9 +61,6 @@ func (f *faceWithCache) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, } func (f *faceWithCache) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) { - f.m.Lock() - defer f.m.Unlock() - if v, ok := f.glyphBoundsCache[r]; ok { return v.bounds, v.advance, v.ok } @@ -87,9 +78,6 @@ func (f *faceWithCache) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance } func (f *faceWithCache) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool) { - f.m.Lock() - defer f.m.Unlock() - if v, ok := f.glyphAdvanceCache[r]; ok { return v.advance, v.ok } @@ -106,9 +94,6 @@ func (f *faceWithCache) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool) { } func (f *faceWithCache) Kern(r0, r1 rune) fixed.Int26_6 { - f.m.Lock() - defer f.m.Unlock() - key := kernCacheKey{r0: r0, r1: r1} if v, ok := f.kernCache[key]; ok { return v