From 2a0a6d21198c3a6f1e133a18169eadcd183752ca Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Wed, 18 Oct 2023 11:06:50 +0300 Subject: [PATCH] fix: data race fix (#64) resolves https://github.com/butuzov/ireturn/issues/63 --- analyzer/internal/config/config.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/analyzer/internal/config/config.go b/analyzer/internal/config/config.go index e2f1aef..46c7317 100644 --- a/analyzer/internal/config/config.go +++ b/analyzer/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "regexp" + "sync" "github.com/butuzov/ireturn/analyzer/internal/types" ) @@ -13,16 +14,13 @@ type defaultConfig struct { List []string // private fields (for search optimization look ups) - init bool + once sync.Once quick uint8 list []*regexp.Regexp } func (config *defaultConfig) Has(i types.IFace) bool { - if !config.init { - config.compileList() - config.init = true - } + config.once.Do(config.compileList) if config.quick&uint8(i.Type) > 0 { return true