From 0175862609e449735b6f7fb560715a52192e33c5 Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Wed, 18 Oct 2023 10:23:07 +0300 Subject: [PATCH] fix: data race fix 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