Skip to content

Commit

Permalink
improved ccForCommonG var with once intializer
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Jun 27, 2023
1 parent f7d141c commit bc71b47
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/logic/build/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package build
//nolint:goimports //so what
import (
"runtime"
"sync"

"github.com/hedzr/evendeep"
"github.com/hedzr/evendeep/flags/cms"
Expand Down Expand Up @@ -160,13 +161,14 @@ func (c *Common) MergeFrom(from *Common) {
}

func ccForCommon() evendeep.DeepCopier {
if ccForCommonG == nil {
onceCcForCommonG.Do(func() {
ccForCommonG = evendeep.New(
evendeep.WithMergeStrategyOpt,
evendeep.WithStrategies(cms.OmitIfEmpty),
)
}
})
return ccForCommonG
}

var ccForCommonG evendeep.DeepCopier
var ccForCommonG evendeep.DeepCopier //nolint:gochecknoglobals // once var here
var onceCcForCommonG sync.Once //nolint:gochecknoglobals // once var here

0 comments on commit bc71b47

Please sign in to comment.